Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

Data Structure & Algorithm Notes

The document describes several sorting algorithms including bubble sort, selection sort, heap sort, and quicksort. It discusses the time complexity of each algorithm and compares their performance on different sized inputs.

Uploaded by

Nishita Kher
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Data Structure & Algorithm Notes

The document describes several sorting algorithms including bubble sort, selection sort, heap sort, and quicksort. It discusses the time complexity of each algorithm and compares their performance on different sized inputs.

Uploaded by

Nishita Kher
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

21

Apptiakiens o nkadLet
Multipu'cauhien
SAddhen
Rupwenta tien e felymomial n Lopute mewou4
Af()= 4
-21 tt
3 - S
A

2 12
c At B

C
t o : 3-sx-
2an- uuk cey
higeAperuw_akied Ls
AAMihm
Aep 1 Tuihalze p& 4 painkus epolyonual Biud
Aist A & 6 upt.ckiely PtAq6
Jhp 2 ALocatrL LL miwou pace
C Larle_A n nodu
dC
kp KLpLatnext kps eith ,S 6
while p 2 NULL and q NULL
&kp 4 C e p t HL ptitrentrpecu aut i

i Cp ExP q ExP)

i 0 hen atash this nad


_uu h Ceidust and 2Rpemet paerp)
uit inked J t C
ATTACH P P , d)
P p NEXT adwac pelnky nxt
9 NEXT PoLihenL
Sp 5 i e E f <4 Ext 2
n attaca ntur nal _ Co q coE
and q EXP"_uhlinked i t C

q NEYT

h n atac wada uih_Cety.P Cocfad eyp


P ExP u h inkd s t C
ATTAHp (otf pa Cx£ dD
Pp NEXT
Sp opystemaini ws pelyuenuta
i (e NUL)

p NEXT
beus o1 poluonua
StpR(pyunAaML
ulc (q NULL
ATTACH Locf 4 Exf,d)
24 NEXT
Sep1 dMEXTNUL
t
C NExT.

SoigAanganLk dak ctewacisdd n aseund


deLcunduna OHda
yLA eopoocaa Soirg
OTatkunal akExkuna SeLhing -
Slab v lwstasl
Tm Cpkxik vs Apac onuplexihy

Ti tpkrihj n G Cenapauaenu

Äxhng kehuLa
i.Bulcek 30tE

ütToeuhen s0t
vQuickSout
Mg oxt
viHeapSosut
VRadiy 40ut

ubble Saxt
Ti conplaxih
T6aN0.dcempauia ou
MApaAisems in Lfa ltPam
Pas 2 t Pan

tPas (N-)
L2

N-)+ (N-2) t +3 22t1


N- 2. x(N-1) * CN--D - D |

(N-)
N
2
Te ceuplexit o(N) but Ca ukst ca
aeuag case

Nad bubble Sosetint AC1 int n


tknAp pass no, -
Aoupakano passnoknjpakno ++)
hpassaa

ii AL12 Ali+])
enup Al1
ALi Ali11L
A+ mp

Selachen Soct nalaele alaokiHa Bauc idka o


Alackion ut ic hat
findfind Ha putit in
Amalleat domnt in giuen List _and putit in
ind 2d smaliaat l u n t in_annainig ltst dnd pu i t
in 22 Pokihen and
Tpomeukatie_ Alucbion u
t t

&elechiensGut_int ALL int N)


OLd
tcmp K , 0c
int n

K: 0 K< N K11)
Cte t i t A [ k ; wun ATXIlec k
2
A i kl i<N itt)
1 in > ALil)

Loc -

tewp ALK
ALK= A[lac1
ALLo c t p

Tme ueuplexih
Time comuplexih ceupasuisekas
ne Lepaise N-,N*2 N3. 3 2,)
NA-)

oN)_s i templkaiy os beat


CLaaiicahitafasameksoo2ing Ageithm
Bpac Copkeriihy
Ti Comupkesi- -
vSuuinbilkhy Aothimmetcd
Salily
vSCxenal a s0uhiug
Takna
VS h-cuoiue uitk e t Mux Aout Rsunuie
Racursie
InsithimAluehon uble nam-Hec)

paxisona
iTins Cgmplarily 1t dapandspm mput size o .
AatHa migumahnga acai
Time CouaplaxihJA H analyss p e g a n i h a i e u r
vaues input z -
tuuchwm exetuln wut input Size
Kale euta a
L uat e4KDLH Hm takun by algoritaa wka
M
Sspesk e vaauA input AiesA

andd wetuto LsKda ssALLsk e


K_cemap.asuisms
poinlesA e d s

i pat Laplsahy

MasyAaabypugsaua jang (lin q d


MomK eAumpim
lecal vauiallu
sto pauautns
fue kem Aalln
Mallec OAunshion
analusis easauut L
pac Loplexih analuA is h
dustin t ta_ExLtutiem
algouiB
(DSake vg Uatabl
when 2 0 w HLLGMdu haue 2a RL Maluu i
LAds in caue e
duplirat kuu
34he od pXuswd auLLLOLdA uh duiaal
Rsalqouithm isAlable

kyialqouitam Js uataleu

ivTnkenal vs Exttnal
Tuknal wh all HALOHd that_nd e be Akd
meouu inkeunalA0Mhing a
Volun dala legs a d allxeLNdL kupt_nkually
nuain wou Auxiliauy 0a HLqLd

Extna: duats ui Aouhiu4 data AtOud in daa


Ais Valu daka i w Lanas and cmet b
heldin emputtn ROHY Auxiau uA A
Hequiud

()Rocuusiug ys o ALuHah
Patu his algoithm salla me wAiuall iNp
NaluA tauns us OsLLLt uatust tnput ak
peo ngopRahonA en_aknudl value jo Amatlen
Amall ipa
input
N uLUMALUe hu
ala6ikm do Laukegall_ a
ML udaout
Tim kciuny - m: LunAe algouithma
hanHOLwAI
Bubble. Sgu Atgo.suiHam
Sep 1 niblalizu pas. 1
Shp 2 Rupaat Akp 3- while paK_N

iniializ pa 0
RupatS8 6 wile i s N-pau
Skp Cpau urce3AOA
iAL>nli1)
dwap (ALiLALit 41)
Sep MAuindgx o next loc

Skp G0 e nextpau
8ek pas pas t l
E la
tHeap-
May hapipaLwt ned has value 4uak Haau hild uede-
A[o3

Al A[ 1

A 1

A heap is daincd as acemplule binaxy h Hho peopexhy


Hhat th ualue eeash nade _atleaat as Laxge aas
he alue oiI eid Men ad L
A AHMax hsap Lec1val

Htap sa is an alothn Hak a equivaleuk k qutkAart


A Aaa Leplexihy allN)
uwstable algauhna.

Hap AAA is_an inplace alaoiHann


9 Ia hap Asut husae 2 phass
PHaSE1 ThiusE phase he axay cenaaining n daka {tms
JA ueued aequiwalenk ka abinauy tun ie at
al
AL aa1 AL31 aLi A[s] AL1 alal akl alkl alol ali1
2 1 8
Pegc.

AT1

ACT

A
12 (13

A81

ashi em haist AulL suiakabnsst-child a


w palr

10

(a)
12
an

ww

i)
(

Soxted Wae

Neue aa becom L

6 2
1 S

the_paxewk e Hu ig
Aep 1 uoes he ned1 whiek is
en he Lewest lemel 4 ih ualue s Haa
MOAt aode
laxgut tild Awap h Aalues attaesuwis
aualue e is
de nething
empaue thz nalues
SHp 2 Ma ut _PM HMeAame Jeue
HhepaMu wih ih_luildML t Anuallu han Ha
Lag hildLwap Mem

Hhen mav wp a leueland bagin uH


paint A AROchud
hedgukruoipasuent_node and upaat emAkpLL
ha pAOALRA &d.
peat_alabesA Akp unil luel 1 wadis
Page

PHASE-2 Stauha em eet

Swap

1
( O

10

(lo
Pa-

plzsaauta.kien ap AoutPha-1
VedANTVST (nt AI int i i n s N
intiint apj

2 ki
ahile C K N ) .
isAL1<aljl)_

i Luap 2 ACj1)
bLaK
AGl1 ALj1
2-
A la1 nnpP-
peukaienBHeap SosutPha

int ) .
MOLd haap- sett( int AL1,
int
Pha 1
Adust (A,i N)
hak
i- N- i:1: i
Jemp _AAL1T,
AlilAli1
AL1+ demp
Ajust (ALL

N
me saplak
N+1
h J(Ntl

A lgouithnaPhas)
AccuduA hiap pepeuhy eet e tue kcs
asugt FRq valut Thu pha oh hsap otut
Har od
wihangutualue and cutsit
in he tue aud Cuts
UhLastyalu

A Swipng htop ditusbid Nes applykap


pm enl en
maii htap (Aizu s a p =N-
AJte appluin htap pop Laxgast Matue-betew
uapLuap aaua eoMalu uiHh ast vaue
vaue
hap Tu puCRAN (minue

#Kadix_ Sout 2
Binaxy MO
Ayskm
lo Dimal no Asslem
Tn uadix 20sut w decemp 042 hesAut Ru
sungAemL_
uadix_L whun i s 10 Leget he_ditimal olerepaiiho
Ina_Hadi sout algauiHon eAaat em t loas
siguiziankdigit_in Hae kuy Ditubuk atu elenant
inksbukch hat Lopand eoible ualues o
hat disitusina FLfO kaod Scan all he bucke
ascendia4 0de andAollLetHheaback into 1
Lut uis uput i l be i p u k 2 p a s and

PHASE1 ( i t digit chuek)


usketa unit digit)
uhpu
Tnput O 1
33 348 361
321

S61 31 143
423 423
2
S38 s
S38
128 366
28
38
3 21 2
S8
366
28
3 6

(shaxt dauukin auckt um 0, f edamnt k faund Pply FLfo


put e eha is nput e a k 2 Chuck ka'a diqiE in
Ten Dat
Input 2
341
361 31
321 32 23
43 2-8
M 23 | 42 S38
SY3 s3 |!43
366 366
348 32
S38 361
128 28 366

Hundicd diakt
Trputo 23 S| 78 0
32 32 28
2 423 3
28 28
3
S38 s38
348
3 3
36
53 S43
348
348 23
361

36C 3 S3

You might also like