handwritten_arrays

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

SoxTINg

peatLAM aan9h dala in eme rulwart


eAd wil may be. ither ascending descendinq
For eramble haue io an amay, A, then ha eleas
n said to h notid

0scending AlOA <A[J <A[0.. <A-)


OR
desendungA[O]> A[U) >A2)> AJ An-1

X orting algeudls a n thL hat arcngesth


olunt oant in certain 0rder, it could be
ordes.
deni cDrphual ary
r u dulinad
po ootiny Teuhniqu

R Ttiunal Jat (B Eceunel Sot.

wuth, nsting the daalo wth ssreling4


dsal,
data in Cmpulus Mmany H data stored j
b y reading o
anday mem
aitigndet-Selutin Sort MugeSot
6uuk Set Bubblu St

TNSERTiON SORT

Tb a aumpl 1ting algodhm


Artad avra ( i)is bullt ome

Ha, the
odemant af a tume

e eduung a dek ecado.

Juhna
to be netid. int tuo nt.
hrvay evaluto
nORTED valuuts.
he steres
othu tons UNOAd valus
ü)
Continu wtil thvu a elumony in AotdseT
)
N Lment, in anay

Anwially th elemant 0
eworttd pastiion has amuy
ftnt
Ant demunt
indes 1 (4 u-o)
ituatn, tint lumant n unaotdyet
Duung 0ah
into creu poitin in
d up and imutdl
Ala6nthm k-1 to N-1
Rabeat tubs 2 to 5 tor
2 t tmb A[]
J -1
3. ut
4. Rubeat wl ttm <= AUJ
ntt At]- AFJ
J J-1

ed inu lap
5 t AlJ+1]- to
6.Evt
OJufhe(elemon
ALO)
i ns k a 39 6 45 63 18 81 l08 54

683 4S6318|a|1o8 54- fan9


los 39 4563|1881 l0854
G18 3945633 108 54-|
fow18 39 4s 63 81 10s S
wil be tha
AJ beita
aml > Al0
Q4M3|554 8311LD8! bu o alur
A[o]
bem
ha
lasm - Ap)i l be
behwtn A[o]4 AlJr
N =-7) PED,in
stal elanmus
=

albr AT:]
am
T

tuarlag aa t imblument and eltiuent to ut

eamall aut o data


Can be tiuily imblsmanted m the data
neto that ae aubetantuall netd
Kaquues lo memmy ba

seRTiDN sORT int A[i,int N)

int , ,t
fr(i1, in;i+t)
mb A[;

L (kunp alj]44 (jv=o)

ajt) kmp
85, 1S,30,9,99,2026
N 4elunants Pam= N-1

35 Isl3o|4|29 2o 26|
aan a]jla[U] uill be ambaseo
a[ etA
a[o) 15 25 30 9 99 2o 24
kemb-15;i-i
1-1 0 wkl ((15 (alo 44 (0>-0))
a[ori]- a[)
ie atra[oj
i-1 5
ao] &5
u e

4L (0-1)/fale
15 afo]
ona Qut

al+= Is
i'e a[0 1S

afo)-25 al1-
SELELTon Dslas 301 91 2o|26 o_2 31

temp =al2]
tem 3 0
- 9-1 1
wk30 < aij 44 (1>-o)) adse

o.+1-lema aP]-30 onl


oktulon
Isas 30
a i-3
emb a[i] =
a{3]=9

L(9alz] (2>:o)u
30 30
al+1)-«ljl ic a3-ap)-
j j1
t
t4 (1>=0)
wi (9 <a[jJ-«ft]
alit)-at) ie al)-al)=2s j -
wiu (9 < a)= IS L&
a [o- tp-1 ai)-a[o j--I
a l Pay
1915 30|49 26
a i 4-
knp- a[1) =a[4]-91
=4-1-3
as7 4 37-0) alye
Lkl99<
30

a[31]- tm -91
ro hangL
altir las 4

d5
emb 2
4 1
4 4>o)t
a [5J- 99
J 3

30
auj-30 j2
tne
lu(a6) 442>:0)
a33- j=1
441Dfalu.

a t - aiti)- a() = knh-d.


a t Yoas
9iso 30|91)4
2 1 S

afor i- 6 4 ik
i-1 = 5

uke36 a[s)
99
44 5>-o) tre
a j+-] ie ale)- aE)=91

Lolde (4 <a[4) LL 4>=o) tu


ati-a) ie a[s]-3t
j3
whil 26 La3] A& 3

=2.
kmp ie ap+j- a[4)
aLjt-
3o

r 17 i ? tominekd
A Jnaling n element nan aMa

nol
1) t v to be inauted at
value
VP ard
.

Qnolg
add 1 to

not peastbS e n d anyrize

iiMiddlu e th ana
fke alomtnl rom hei
to move hal
Ha demert.
nw
Q u e m o d a l enpaiu
or
p e o n to

wha we do
do do tun
un Svto rder
hrange
lotatuon whee elmen nnd
Fid u
to be ivmeuted

en mev all 4he eluntrig valuu hawnq


than heo iltment) mu peuionto
realir
the rqht

THERT(A, N, POs VA
ki dtment haoto bivsedel
shere A anay u
N no.e umunt, in ama
beetd,
at Lofki demad hayto
PoS Po
VAL Vadlue fo bu tiatuted
Ngo
-N etal na sumal,in
TnuialinSed o
upot stapo 3and 4-
I>= P0S

set ALt1] AT] elamu.st, to


Crestu p
Ad I= T-1; f r nes dame

d lo
A N Nt1 au irtsttol

6Aut A[Pos]= vAL


it

tMample 4o 20 30
10 SD18
ACO) AC) A) A( A[V) ASJ

Calli TrydA, 6,3,100 val )


pos wklu(i >=3)
ALit)-AL
80 16 sD1 :it1)
4o 20
40 2 30 10

skil(-3) tue
a t a het mean

4o 1 3o| 1o so 18
af) a[6)
-4
- 3 te

L-ol4

3 tre 4-)

4o Do J3o1o1oo

4o2opo10

66t1 -
A 3= val -100
ltung an lumun
dala pm lng 0unruu
Kmouung a

a{u
slendet is at nd, then
herbound -

a t at mddle DELETELA N, POs)


lannt femukus
elenthea
b e d d e k e

om wlert unut ha,


Aeaut i-s Ledolkked
(2t 3 4 wle il= N
A
ad A)- .l+1) htmen

at i+1

ud n-1 yduUrtmelin
th thau.
At n-

al te elomu kauing
aN
a n

He, w il move

undet qyedor han PO Ne ahau teoad, i t


eupy He opau
vauat+A 6y t« deletd elemut.

Deldiy= vaituy slenunt ttk valuu ef t


0

lo) A[ A) ALJA[4) A(5) N


Calling Delude(A, 6,.
LokLu [i<=6-1)
5 tru
a[2]- a[3]+1=3.

1s 2 34 4-5s6o
3=5 tus
al3j-a(4 i = 4
56 16
4s 2234A3 AL9
y-5 tu
[ J - a l s J i - 5

42234-1s |6o
S( 5 ue
a3-a[) y luxh
faafya)a[4)
j i-1 aU)

(6)nen-1 {S
dHan
33dL op 22
Hhen aopy
Contat, of 1toupinb
3 a r a y ContaNs
Thd mo
oy Conteat 2 nd eeytot
1t

Oay ursntd kunl t do


heed to oo fe
but both enap artintcd we

Nug-
Agttd
AL h

ttora AL
tnter mons f piat A2 n

h2
edemanl 3" ona ) =
n,t
Meo o
i-0,i nd; itt)
a314)-o
jtt
For(i-0i(nz-;ltt
3 1 - a2ti;
O , in;j47

ptf Meqed o pmatfal


A1

lu(1ni 2n3)

a adlj J- a1[1);

aL a2[ 23
2t

1-n1
Loll(j2- n2)
a3[- a2[i2);
jtt

shj1<n1).
:41,1t

You might also like