Professional Documents
Culture Documents
Indirg: Fovevery Fond Suce Emsul
Indirg: Fovevery Fond Suce Emsul
8 seaschin
the Operation to
Searehra sefens to
IheTe
fovevery searck techniu
a outcomaa
Page 20
Seareh iAt
a Key element
3 t {unction Option.
There o 3 Searching agorithma
1Linear Search Data i in n-ovdered ashim.
made in
earchi a Te cord (or) tttm inthe
lgovithm
lgosithm Linea carch (A, Tm, Ket)
CtureNotes.
mpu A a y C I havinR n elerments ond
elememE Ho be found
aaput Key elomem locaien in axyaA
AC1 euals k
rekurn f locian found
Teturn \
Page 22
Page 22
Qray elemen
the behind thia Hechnique i given belouu
ogic
) Firat find the midd element an aray
Ca Li Te NOtes.In
a) 4 t i deired item them Aeach is 8ucee
b T t is l e than he desiwed item hen
seasch only im ihe 4 holf ot an a r r
c) T4 t ib greatex harm the dexirad tem they
Search i n he a" alf dt an arro
he TOe CompariAU
X o tima te can divide aryo elements
by '2 upto
ou have elemen
do he log2
lo3,(2) lea,(u)
l e s leqN
The complanity
beat-Cask 4ime Ou
The uorat -
Set midmid+l
e
sel right mid-
En uhie loop es.ln
eturn i,
Page 25
19SerEirg Techniues
w ww
Page 25
9
w
Sertina
mmw
Techniues
romgi the elemems eitter ascending orde
in deAcemdir order is called Sortin.
i intexnal Sorting
i) Exkernol
nteral Sarhig All 4he TeCords that o to be
orted in moim menAr
Sort
CctuIeNotes.in
na
Soring Eater TeMegea)
SortiresMergea)
Natutal
ealancad
Tuevtion Secion Echange pcly phaae
Sfwntion selectim Bauble
Shell Heap quickK
InseTion St
Jninertion 60rt Ahe Can be
devided nto
ProceSt
AC1 b self ia tivallu Aorted
ither before or affea
propen plac
in Alo]
AC21 is inuented into %
Au
Thi Proc% isepeated al elemenK
in ATHes ordentes. 1 n
Enample - ray t
i
The Jiven om
plaCu
a3, T8, G5, 18, 32,16
8387
pax a Gs unth &rhed ust
Cempari
78 45 omd 83745 (F) So
785(T) a3, ?, 18,18,32,10
a345(F) a3, 45, 78, 18,32,o
Page 27
Comparing 32 h e orted u b s
18,23,us amd 15
, tt Conditian uiE
true change tne pokition o ge
elemenF
15>3T 18,23, us,2 T5,10
uS 3 2 T 18, 23 2 ,us,15, 10
13, 23,32, 45,15, 10 ^Na chans
o th the oted ubli st
Comparo
18,23, 3 , us amd 15.
1S >10 T 18,23, 32,1S,? 15
1 2332,n us,15s
3210 T 1,23, 2.345,15
a3 o T
18,2,23,32,4S,1ns
18 10 Te 2, 18,2332-,45. 15
lo, 18, 23 3,4S, 15.
finally Ou sorFed aYO eluma OJl
0, 1,2, 3 u S , 15.
Algori thm
Algorithm inserstion. 3ort CA,n)
StaThr
amd
aRead al the elemenh o an arta
Stose Ahem nto
an arajALS
3 Repeat Step omd Step 6 Hor K 2,3.4----D
End.
Time complenut
TTeede d in cach ay
NO oF Cempanin on
in uorst cau
(n-
S(Y-2znan)
OCn).
worat-Cage
T ot)|
Compleitt
Sele ction Sort
Inirat atep the malleat elumamt eanc
-firat poRitian.
Now the Us iy divided into tu paTt3 .
a ored
is lo, it a erchampe
t the firat elumemt
minimun euman
ecaPt
Fndi the
element i
18, it a enchomge ui th
4elamemt in mrted i a ) nith
aTelamen}t
Page 30
S(n-Y
Algorithm:
Algorithm Seletion 01t (An)
Start
a Read al he elemen &an aTaomd
kore he elumen into aray AC1
3-
Repeat stepG and step s -jar k=1,2 n
Call min(A. K,D, loc)
6 Tatr
amge nik] and A[loc]
Se
temp =
A[k)
LLac tomp
End o Step3 lcop
Butble Sr
Bubble Sot a auko calld a Snki (o) Exchage Sot
nbubd ort , each lermeoneia compared
adgacen* elomamt
h e econd On
largen Aham
T4he firat elament
he elumemh intenchaungeA
then the postion
i) Othevie, ihe potitien h e elumens on
chamged
The Soma
o lefF Jor Cmpaia
Aftn the 4t o he arga elm ent a Pacad
in - " locaion.
16
Sep
1 is checKiT t h 4, Sinew 1>a, enchange elumamls
as8 3 9 16
Pas 3
Step
y chetking ls th 6, a>6 (False), Nochog
839 1.16
Sfep
Chetkig usth 8, 678(Falbe), No choge
SFep as 8 3
s chtkima usith 3, 8>3,Erchoge & 3
a 63 8 14 1
Step a 6 3 8 4 16
a6 3 8
3 8 IG
8 R 16
SEep 3 t a3 6
6 Che Cki»g i i h 8, 678 (Fal») No chomR
a 3 6 84 16
step
8 checka sth , 8>u (true) , Eacbarg8 by
a 6 u& IG
Pas S
SFeP-
Checrima sith 3, a>3 (Fale),
Ne chong
3G 8 G
SteP
ChetkiTg uith 6, 376(Fai ), Nocharg9
Sep3-
s by
Checria utb 4, 6>a,Eicharge
6
a3 S 8
Le
pas'-
StePl
Stepl
3>3(Fal«s)
No Chang
& V checkim rih 3,
å 3 4 G8 IG
Stept
3a>3(Falzs) No chamg)
& checkig Hh 3,
3 4 G8 .
Page 34
lgori th:
lqoithm bubdSort (A,n)
Start
a Read aray elumenh and inant Imto g7ray at
3. set :=o',
ACi+: temp,
End
Time csnplunitt-
oJive
FToh Ate enassopla x Ioh the Ashed
elumams ou 8.
nihe pos , So ihe mo
Tola pos uired for n elemen-S A
o
-1
TO S - 9 4 (n-)
(n-nY
-2n+1)
Aorat-caxsTm
+timas Comdeai.
On
sorti Teehngue Timu cemple
Sovin Technigsue
Inaesthon &ot oCn) o()
Sclechon Soxt O() o() Oln)
Bubble Sor O ol)
ofnegm) o)
o(nagn)
Rodin Sst O(nx) O(nx) DCnK)
Mevge oT o(nlogm) onlogn) olnlagn)
olnlegn onieg
Heap Sot onlgn)
Search Techsiyua, Timd Omplkn