0% found this document useful (0 votes)
18 views

daa- unit 1

Aktu DAA Unit 1 hand Written Notes

Uploaded by

itskanishka1202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
18 views

daa- unit 1

Aktu DAA Unit 1 hand Written Notes

Uploaded by

itskanishka1202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 67
Unit-1- Introduction Algositnm : Algooithm us dhe det of cules do obtain Yhu expected output from the given input [ Probtem | Algosi-thn | { Program| [Compile We cmalyse ony algowrthm with sespect to dwoo posiameters Time onc Space Complexity of Algosithm : Time Complexity: Rules: G) Single Statement : Time Complexity Oct) diy hoop: fr , le ton n S@ g+ afi] hm Tend= An = O(n) We neglect the congtrnt values while coorting tho time complexity (general ) PRBR RP RR eee dJodbve ts DF FUGUE L » m case of polynomial equations re 6nte ane we eorite dhe highest olegree team oce) Gi Nested hoop : ‘for l— itm ™ Pr ea tm mm =m? Se S+aft] om? Te Ten) = m+am> = m? = 0(m) Ww Tf-else : 25 + lt Gt (fF é] —* O(a) <——— (vy) While. Laep : "170 ve ttt n mn ne on Jog n j Ten) = O(n) a, "} yy PTT TTY o ii// oO (ify i// Se OVETSSSFHSSEUHKDKHHDEHEUHTHOHOHHH HEHEHE EBEEDEEEE ES Wi) Recursion : fact Cm) +b met 4 vetuin (1) else setusin : fack (-1) ” Ten) = O(n) Example ci) Sub Casn) t S=a.0 for. l= adton obo n S= $t+acij ‘ wetusin § ‘ 5 — Tor) = atan= O(n) Example (ii) Proctuct (a(i---m, en], b[I---b, --p]) a v1 dom do ™ i Jetdvp do mp CLijl =o bmp for keidon do hmpem C[ijlsclojlealikle blkg] -mpan vetunn Clim i---p] 1 ee Ten) = m+mp+ mp +mpn +mpn +} = mHmMp+ 2mMpn + Ten) = OCmpn) Example (iii) te tton mn Ac Atatil mm Be B+ bLiy in for JIS 4 fop mp ie pe Kelby mpm C[tjl=o Inpm B- Arc 1-npm TIM = 0 (mpm) ADD DADA IIIAI DIMA REM HHNHNAAAAVAYLIVIY NS CSHECHCUHHUUKUUDUUHEHUY EY AEF Sf I OEE OUR OTR OU OTP OT TE Od OIF UF Ire OO re Pe iP w@dddda i f svoaod booed bu dd a Grrow'th ef function : t0 Such dhat for all integer nen. dhen Bh19 2 en += cgey Gea foo = Cg 3 rhe hz) Ky - SICh Theta Notation: (tight bounds) The lows and ubbex bound for the function f(x) fs provictect by dhe ‘6! notation ‘fos on -negative function 7 and gc dheie euist an incleger Mo and posrhve constants Cc, ad Cc, te @>o CG >0 Such thot for alt inkegen m=, Shen Cagen) £ Fem) £ Ca gen) }\ }} HY} FE PEEP FFP EE-FREEF Hf th ITA a3 y, \ VOSS PSO ONDE UE GE GE EDEGEEGYE EDGE Y YY Uw wy Sowing Recusurence : These ae thoiee methods to solve sieawwutrence U7 Masten Me+thod /-theorem (ii] Substtution Method Ckexotien Method ) Uy Reeusisicm tree Method me Master Method : Master Method is used for Solving dhe follocoing types Of Recusuience Ton) =a TQ + feu Qazl od b>1 m dhis, the problem us civiotoat Frefo cub problems €ach of size a where a,b ax postive constomts, the cost of clivicking the problem ond combining he results of dhe sub problems us ctescoibe by femction Fon Mastex theorem : wt Tor) be defined on the man- negative Fabeges by dhe wecurvrence , the vanning — time Ten) cam be Tes = & TG) ie cone a2i and b>! ‘Then Ton) cam be bound asymptotically ax followect Method 4: '$ fon my 2G, then Ten) = © (fen) ® my 2222277220 IEEEEEEL LL a2? aa a9” — nz az Ere PTAA PP Pee Lr OOCOEEUEDI bd ddd e ro oifoodgf a, badd SE SSL eed dad’ Exa) Solve tne Recusoience using Masters Theorem Tem) = 9T es) +n Compasie Yro Given TecuwHeNce Goth - n Ten) = at () + fo we get a weg b=3 fend =m Now, m Log,,0 tog, 9 a ' tog (3) m 2 -t0g,° an Compane osith value of fcr) fen en n> Mesthool 3 1s applied Tend = ©($¢n)) = @(73) Ton) = 7 C*) +1 Solve at by Masten Theorem Com pose Tem) = aT ©) + fcn) azl b=% Fem) =! on OG mn Ba, l me 4 wo ° fey =i Case 2 oppdiedt Ten) = 0(786% Lop m o(1 togn ) N v) Ten) = 3 (7p) + 7 dog Com pase Ten= at Lb) 4 gov a=3 b=4 fer) = ndogn on 28 Ee on 0g, 3) nis Now, fon) = nogm > nis Cage gr applied Te = OC Fir) = 8 (rlog n) vi Ten) = et CB) + A Compare Ter) = aT Got fm) a=l6 be 4 fo- dn nO Iu '6 ™> Nee pened

> m? Case att applied Ten = © (F(™)) > o(w) Wil) Tem) = at (24) + mdogen OPS Pee er be fob hehe RPP Pa aaa POOH EDTOH HEHEHE HU UU UY YUUYwUt — > Compane > a=y i b= 2/5 Ls Fer) = ndtogn L + Now, L 229 50 Sag ys Le om B44, L > 3. > 2 Fou - ndogn > m-? Cage gro Ten) = ©C-Ftny) ~ © (nbogn © Ten) ar ¢ OF) +m Compasie a=3 b = 1% Fony= 84 a in Mg mos Now, fon) an < mos Cose ist Abplical To) = 9 Cres ) GC Ten) = er (HY) + 3m? Compare a=g b=a fon) = 3n2 QO 4 \-\-\5 \\o © \\ savavovgaaqaqaqqay yyy 229293499 IF ALLLI PATTI IIT E ba ee weds uh fu fb bbe huh DESRUVEVEUE J‘ SCRA ik Now, log bo on 40958 ms fm = an? 0 Tom) = -T(m-1) 40 Ten = Teagan —O = T(m-2) +(m-1) +0 poe aed tna = Tema) 4 (m-2) + (m-1 4m Ten) = T(m-a)+Cn-1) ' put n= 0-2 In (iy = TOK) + (m= CEN) J+ (m= C12) + (M- (ie 3)) + ---4m-1 +H Tm-2) = TCm-3) + (m-2) © TUn-K) + (ne Kay (MK 42) + (- K43) 4--- 40-14 ata dime kK will be equal oy > TCm-n)4 CM-N41) + Cm 42) +(M-143 Jt- gn 4H = I+l+2 43 44 ---- 4m . t+ mM Cnt) 2 aa Wan 2 OG) / Ke FF HEEKEKER G@9aE@ i UH HH dha TPT TT TT 4aD AGS rtf He SEE GD DEED HOOT HCYUY HE UCUYYUYE RREEEEEL IPI Pi Tibi i ie o sho babs veeUIVEVS Wd Ahh oek Wi) tomy 2 Fo 15 Af ner aT (B)tn 7 N>1 Tend = at (Bam Ten) -ar(h)+n *#[aea] rn TD ar(ay (%). ar( M), . HT(B)anaa oe? . a [ar(B)+ 3 ]4an ars) 37 ee . ar (hem Hakivg dog, both dhe sides dogm = log, a® deg Eiage dogn = Kk = ™TC) 4 mdogn Ton Teny- gey CH) Kn ru O(mLogen ) 2 mt (B)4 nogn 8 "Recusiion Tee Me-+thod - Reawrwion Tree Methocl us a pictorial represontalim of a dibesation method, which us in dhe form of tree cohere at each Jewel necles axe expomdact. dn genesiol | we consiclen second term in Teeunnence as yoot. ut is useful whon olevide ancl — congc.os1 algosithm ug used Exci) Solve given vecursence by Tecusision Tree Methocl Ten) = ' fmel ar(B)+mn yn repjat(ypen oT Mn x1, ak =n m=ak log = dogak = om K = togn 2k “Rn = kn Ten = Joan ny yy SITCEECUNRUUNEN Rd ddddddadea/ada/se/a/sa/lale/eae/a/a/daaia rl 999999 /rPrrerrerr et ol tt tm te Nt ee /; wwe « ddd CUT CUWee bbb e PELELLLES PPP PPP ves bE SE et eC S Ton) = Ta) Ce) ae | pk Me, = aie! f ms 3k @ -1 log n = K dog 3 Jegy - dog 4 Ke dog Tony= Kn . 0g, mim _ z len) “afr te n 83") NOTE: We always Congiclen Yre lorigest value of K becauge ut usu give dhe Complct'ty of coorat case - here Pr the above question lyk sicke até give best Case cohow ag Raghct Bole andl give wasrat cage . ‘VG Gi) Tony F(R) 4T CHE) + QO & \ \\o db Bacar Solve dhe given secusuunce by secuntive tree Me-+thool ne tsk of Loft seo! © \' heaped eg Past © 4kn Sk me Be Meg eK i 199d Gg q' @ ® 9999 Ten) = Ky wislougen) YO w 9 94392 2APDAAPP wy) Ww) Ten = TCA) + (2) + 7 Tey-O(7 429 wo ") Sowe by Reoussion Tree Methool: 2 Tony = aT( B)+rv , Tew = TCR) + 1) tm ch ae pe 2 4 a 1 gc x, we firte ts Ey] —) GP = x ma . ant _ ne Tey = o(m*) Sowting : Bubble Soxst: Bubble Sost algositnm known ag exehange Soest, us a simplo sosting algorithm . dt works by Compasuing woo items at a ctme and Swapping thom of they ow in crong order, ‘The pass hevoug h dho st us sepeatecl cmtil PA swop 050 ravctec, which means ist us Sorted. tt Js algo cattod compasuson A6rt: Comploxity of bubble sort = O¢m) Nh Fee E Bubble Sovt. Aigosrthm : t for 1<— 1 do congth (A) 2- for ja Lang th (A) clown do ty 3- ff alit< aca 4- €xchomge CACII, ALI); TiPRRR RE RE HP Sosk He follocaing efoment by Bubbl: Sort : A= 18316, 68,5 THFFFF FP IS 16, 6,8,¢ fass-4 VS 8, G ,16,8,¢ ' Ry 1S,6,8, 16, © aw <= aN 16,8. ©, [16] aos a4 es s wuwuet « Sess EEE HY CW bbbibb bE LLLLi ise TTT TT TIE) WHSREBIOS i \S,6,8,8, 16 at 6.18,8,5, 16 p. “As ‘ass- 2. G,8,18,5 as 6,8,S, [1ST 16 68,5 ,15,1¢ ws 68,5518, 16 ie fass- 6,5, 8,18, 16 5 “as 56,8, 16 ,16 fass-y Complexity : 142434+U4----4+ N45 nm) 2 ote 2 Ten) = SC?) To sort dhe follocoiveg element by Bulle Soxt as [5]2] 1 [4] 3] 7/4] r23 4 667 urgth A=T tei—7 J=7-2 (2+) Now, . . v=) fe7 ALj] = AL7I = 6 ACs-d* ALS =7 AISI < ALS] Atiy< Ale] é< 7 5 True exchange A[7] md A[6] Now orrray 2[1 [s[s [el7] poz 67 of : a Novo, t=4 J=6 ACj] = Al6] = © A [s-1J =A[5J = 3 Ale) < a[s] é< 3 False No exchange [s[2 Teste 123 4 5 6 . LAY “EFF Me df, dt al ai asladasawlastatlala/s«sa o® 4 7 PPT) TTT 7 ~~ — (Pit pippp usa gs ACs] < aul 3.< 4 True. exchamgeALS] and A [uy] Now asviay is: CPEE Is Iel7) 12 3 4 § 6 TF ba gey Atyy < A[al $<) False wo No exchange. tsi Je3 Als} < Ale] I< 2 True exchonge A[3] and A[2} Now assy 18+ [5[']2 3] sfe] 7] 4 2 » ~ 24 4 > 7234s 6 3 2 3 2 » 2 “5 Now); vi g- 2 A[2] < A[+] ' nl = n(n) 2 = vn 2 Ti = ot) Sovt de following Aeviay using golockien Bort a [S| 2] 1] 413] _ o \ 304 SF ALt] < ACsmaliest Al27 < ALS a a u< 2 Folte. ee, (usb smaLust = 9 > Alsi< AL2) ae 3 <2 Today. ir preninste & [2 [4B 4 4 4 4 4 2 2 7 Neto | J=3 Smattes} = 3 | T= 4 dos [ew smadtlest - 3} Alu] < As] 4 <5 5 True -S — gmattest=y Als] < Alay 3 << 4 3 Tous . nr ge tld = 4 smalust=5 92d, *% Exchemge Asi, Abit = '[2]3]4]s5 | News 7 - j azy Smallest = 4 / i === i a ues T=5 - Smodgt 4 Alsy < ALU] 5 <4 re ib False . gel! 47 Sovted apsay Sill be - (eer) ~ yy) +} " EEF EEEEEEEEH-EEEFEEFE HY) ? if 2 | eeeewvneweed ee i Phe Ae RP PPP PPP aE Gy Sobbd ded bE EC ddd dd de a re Pe a - . 1 : > > a 2D > 2 4 o WOM Teton Sort: msesction Sosking us One qhat soot A Bet value by mrsercting value into am existing Sortecl volue Algosithm : i- for Je 2 do Length LAl : 2- alo key<- ALIT 3- te j-t 4- cohile (iro & ALil > key ) i 5- do ALTHICALI 6- tet 5 7-) ALI O Key j Exomple: Sord the following element by meet on srt 965 0,8,2,7,13 y jh a= BEE ofe]2[7] [3] Kae oe (6/9 [so}sjay7fi 3] Oe (5|e[3 Joys 2;7filz I [ols]éja[slal7 '[3] (of ]¢[8[3]2)7 [1] 3] Execution : 123 4 § [a |e] sfo[s d= 405 28 “key = ALA > ABI = 6 teq-e4 T>0 & ALi] > key 9> 6 Tou ALHI<- AGI ALzTe 9 L=t-1 ihe Bh 0 pe Sh A [vst] <— key A [ort] < 6 GEE < os 8 HyFHN) Hy rrrry. TPP a ® TTT (fff DP PEPD THT ‘p bape be bP PEELE PEEP EEE A bbesdbeddeuorreeeeee” + dsb ds Ee ee Er Ty ea u Ww | key = Aj] > Als] > 5 tejriea iso 8 Ale} > key 9>5 True AL it] AU Aa) < Ale] A{3al <— 9 Wea = Ol a iso SALI > key Alt] > key 6>5 Tu ALing & ALI Abie te zi-l=o False Alon] — key Alt]<—5 5[é[ alos | Hoe ) 7 H a key = 0 Us gt = u1=3 Alter © AL Alu] < 9 UsGl 2 Z-tao A(t] © Att] ABI <6 stl sary Az] © AL Able 5 t2trsbe0 AtI— kay ,ABIeo {o 5/6|9/8 JES 28 Opt 4 Time Complexity of; msexctien Bost : Comploxity = comparison + movement d-Q = ' + | 55 = + 2 a-4 = + 3 set = (m1) + (n-1) Ten) = 80.0422) + 23) ---- 4 2-1) afan(m-1) [men] oc) = eeeee “THF q } SUNNY LLL TPPET rrr} I, GdU¢ yy de rrrhy) / LOCC ECOCLECLLL > =| & bbb bbb bee uuuueeuueeuee vs SoSHISSSSS a Pre- Requiget for Heap Sort, : Binary Tree B Representation Full binosy Tree Complete fainas Tree > Max heap > Min hoop maesction and oletetion heap sost algo: Binary Tree omel Array Rebresentotion : i223 4 s¢789 10 s[2ufsle alalz Grray Represertation) 123 4 € 67 (2[5]é] elo [zfs [is[2 a | [2 | = ad. tt position Left chilled = aicindey Right chile = ait poxents oF es 2 Full Binasuy Tree: atl nodes have two child except fermtiosrioce (eof nocle) a oo Qo x ‘apie © ®O ® Fo o ee Complate Binasy Tree Jb @) (® RO SLdd @ ® S 6 A Binasuy Tee having wo cluld at each wel except uot rode ( feof cnocte com have one clutel) All Futl Binasey Tree osu Complete Sinaxy Tree. 3 (Comptcte Binasuy Tree’) [IEE & oN ene ee om en oN oe one oes es —e Sas “Ss “Ss ~~ Se SS ons ~~ ~~ Ne. VIAIIIFIAIIVIIII TF Sd DF aoe HHHHHEOKHOKHEOKECeHEL Heap: A Binasy heap data sisucteie 8 an avwiay that con be view as a complete bincvy Tiee. Foch nolo of dhe binary free Comesponcls to ameotomat of He asxciay. The aseiay us completely filled ot alt Luoots expt - pecsibly Lowest (Lost) evel @) 8 © © ©@ ® Heap sree = no: of elements 5 Mao property : Max Heab: A Heap us called max heap 06 dlecenchiig heap af evesuy mode of heap has a volue greater thom or equal dhe valu Of ewenty child of dhat node Alfred (J = ALI (18) 6) (a) OmOROMO) Min heap: A heap us cable men heap ov acondliing fash ig cuouy nod of hanp fas 0 Wl lus dham or equal ao the value of ewer child of lot node: ALfonent (1) £ AL (8) [se[4o lus as [se [25 31 [2/37] insert 705 (50) (40) US) & @ © @ @) O® UTAEEERAS FOREMAN PALE AEADAEaAaog? UULt CCU * ooh Sorc algo : Heap Sost CA) Builol- max- heap ca) 2 for te tangth Ca] clown tod 3- oo exchange AG] < afi] = heap - size ca) Hoop size (A)-! 5- Max - Heapify CAs) Build-Max- Heap CArt) 1- Heob- size (A) <— length (A): a for te | ae | down do 1 3- Max Heapity CAI) Max- Heapify CAsi) S- he Qt [0] a 8 & Right C1] 3- if A ALI 4 then Aosigest ot S- else Aorgest — 4, 6- i v4 heob- size (A) BACB) S A (Hasiges +) 7 then Lo51ges4+ < Br hosigest # 7 3- Then exchange CATIT, A [Longest] } _ We Max ~ heapity CA, Losi gest ) “FEES aiayy rer eo anOOe Tr aeele/ HITT PUI LENTIL DIEIOOD® MELEE CELLET ~— 9 besedseuuus Rhee Ett SSO rt s- > WWuustsote de ebexation of builel Max-heafb on tw A= £5,3,17. jo,84, 19, 622,90 | BA] < [Sf Ls] Meab size A=9 So fisst we call max- heaprfy CAM) ofter max-hoapity G4) After max heabify CA) Soot He following ortay using leap soot A=$4,1,3,2, 16,9, 10,14, 8,7 ¢ Afien max heobify (AS) , No exchange | VYVVADRNAHAKMRAKARKAEKR } TEDL IIT PP ryry / 7 9 7% 4H % a) aj a TITEL SOOO "SOSS after max-hoapify (A2) after max. heapify (As!) Again max heobify (2) @) (9 ® O@® © ® OO After thin we sort the eloments- Q OO @® @™@@ © @ 2 Oo ® O® Now e heapity Je “foe ©®@ Nowo Max hoapify Bh Now max hoaprfy : ® . “= “Bs CORORORG) QPEEEEEEPEPRPOPOPROFTHAANRDA THULE ELE LU ADYANAHMANRNAAAAAA TPP rrrn yo» Noto Max~heapify : @) Q ALO > gq ® ® OO ®) O® ©@O@G@O®B Now Max hoabify : (2) Q QS 7 & © O@® OD M@OHH@O Now “ > gr © DOOOHO®O Now max hoapify ay + & OOOOOO ® Now max hoabify : sv + &§ © © O0HOO OO Sosck dhe etement by heap Sort: [4:13,2.16,9, 10,148.75 v=5 ‘Y= 10 B= NL |O< jo T>16 , Fake dargest=5 (No exchange } 9410 B>1U , False B#t M#Q (exchange gerd) COCO NHHHARAHAAKA! ihr ELI On © Wi) (iceeeeced ends! ev as € LLLLLLIJI III IIL dd GUUUureceeeeee L usseseeers ak © Gutck sort: Gueck gost us based en clevide ond conquor Tule, Divickea[P .-- into ALP.--- 4-1] and af an -¥] Ale. - >] IN A[P--- 4-1] ALU oJ suchthat — ALP--41] 4 ata] e AL qa] Conquer, shost dhe sub asviay Tecwesivelys Combine, extize ase A[P--%J] us moto sosted. . Guuek Sosd algonithm coosks like posdttion- ving the aswiay do be gosded amd each postition fn terms gorxted vectwisively. Im pasctidion, one ef tho cvviay eforment B Choosen 8 a key valwwe- dhis key value can be dhe fisat efoment ef sho asojay. Rest of de csray elomerds wu grouped Selo oo Postion Such ag- di) one postion contains eloments smatte Yvhan Yho key value. Gy Anothes postion contatns elements Lasiger dha Yu key value Algo: [pon [| tn | volue < key Key key < volua | 4-1 | ai] fant-1 key — foot-2 (P--- 41) (te 8) Frrstelement wor | 6 dastetem el Quick Sost CAP.¥) 4- Tf Pew dhen a- ge 4- 4<— PARTITION CAVA) Quick soot CA,P, 4-1) Quick sost CA. % ) PARTITION CA; P,5) woot | ke how last element as pivot mC! SY) Xe A[r] ta Pd fos GP dort olo Ft ALIS %* Yhon te Trt exchange Alil<— Ati] exchange ALi] <— ALr] wetwin 44 a, EPEEFEEE TP rT TH HOMANMAAABA’ I 4 POODDDDHMODNE GUCLCOOLELELL LLL) PP Le RELERD oo” id ida Ex: Rerform Quick Sost : § 51,2, 9,0, 8,15 ¢ [e]' 2 [3 [o[8[ 3] t Pivot G2.0 (EE LI9 13 ¥ RES P PP of 2 f, [8.9.13 TPF Pp P p | ig Ex: Perform Quick Soot: {610,5,9,2,1,15,7f Pvt, (6.5, 2, L 7) 7][9, 10, 15 fF Fivot N I o 3° a = 6 El Ntdsttdetl df ffl LEE LEE LLL SSS dd dda’ ‘] ee oe a [2[ 8]7|i fais] sla Atv] xy P “™ ~o —~e —_» —~_9 ~~ Tt Soot = gna elise by mange sort + [5 [47 'f3fale| E Z - \ = Divicke [5]a a7] ("3/2 [¢| kN Ls Ge) Ei] [1B] (le Bi) EH) Cis) Bel Jafalsty[s[ef 7 a" [alsa [i]2[3Je] Merge rN ron BEIT] ft Ba /\ /Al 7 St ral JH WB) Glel Sort the given clomecd by merge sort is] 5] 24] 6] 113] Je] 10) 20 Z y is]5 [247 ey) [BJF 10 [26] YN JN is}s]au) [eli] [Spe] feysa vy vy vy vy 8/5] b EJ) Elie fio) bd vy v i en ee vid ik BH E lid Be [Ts[s] e] vel sy ig] ae] 94) tr Denes L s |2 Le | . LT sls] x ie 5] 15] 24] lid Ue Pe SIEM /\ S/\. SN od fl (a) Diviole Merge \ HeAMR OEE HAAR: HEAERERRP +h e/e ULL ETRE 2 OBBRBDPAPREBPOO CCOCLOLLE EELS ” SOTO TC CH dd Ssot Merge Sort. algo execution: p []2]2 [5] 4s [6 7] to 34 las 4 2[*[s]7] [Pls é] sh aa M= 8-4= 4 1 UGE) ethers thts Fsaae xP 2 3 4 ao Counting Sovt : Coumt Sort assume chat each of; the nn input elomeuts fg am integen in He wonge Ld4ok, for some integen K ushen k= O(n) dhe govt sum fn O(m) dimes. The basic jolea of count 20st ds do uterine for each Prput otement x, dhe mumber ef lament lers ham oc. his info can be used do place element oc durvectly Into its posttion fi. dre output asciay Algosithm : Counting Sort CAB, K) 1 for t-odok a do CliJ —o 3- for j= 1 to dengt [A] 4 doc Cacia] — c[arsj+4 5 for f= 140k 6 do Clid Anan nasa c ESTE EEDEE PEEP PE DPE E —_ om rm «0 Ps ~) a | all = | «0 oo | | 5 ie "es woo ei --- ~) OO] ---4 wl “ 9) Ul oi wo] 9 n wb ee mr b | ot gt i ~—! cot . Ala sy) i ee » 9 ey 9) mea ' Lot ter a! ale ey te 7 ‘ Lessee; foyer an j how Pw > 6 € seo geo ge % a cr = u Mt t to u 10. 8 9g 10 A Mm a = [4 ) al -| a2 aa t4 >: x] yt oo = wis alee oval “P| IE Vi o p blo bv ra Y)c0 21 65 sO va] zl 7 be-! _ ~-1 A @ 56) 1 r/Ol aa 9 agi I ala} SL mes mala Eel alse a “ly —i a Foe alo ola OLS -L joa eo uw oa " 4 “ ei . a oO ao < o §& \ = % % 2 = = é z z mA TEEPE PPR RT TD iT (T(r eres =lo) Slo Os Ona Pe) et oi gt oO wy Ms al --- al ue. Bay Pra ee > a | 8! al —\ aL? bona eta alo teas Tole: 1 -fele:o l=) bee om oa oO POSURE LL idddd edt 4 > = fa 4 ‘ 2 a i 3 eS ,oF 5 a s =) Sacto “uo 3 YI OG 1408 ji [a[s[s oO} 243] of 3 © 1 rrene Oo! a } @ etl Bost the given element by Coumting sort 10,7,12,4, 9,13 K= 413 Ss m3 Y \ Step y- SRP yon gy s 6 ~ W4}7 9 12 [x3 ce #848 ,1 8 9 Io N92 BB = “ToT hae Wag We fae Ss ' PSU Aye Ge 8 Step7- 123 4 5 6 4 79] 10] 12] 13 eae Sh I IO eg c= ot 15 1212 ra ry ry 1s! ie ie eh eh le ee OE Se le F ” Radwoc Sost :- Race ost 8 a sosting algo Shot us Useful when dhe uw a constant ‘d’ such dhat all he key ase ol’ clugit aurmber. do execute actos gost Pei cowwasols ‘qd’ gost eo mumbo with sespect do dhe = pth cligtt fom dhe wight using any toan time sort. The code for sacha sost us stratg lt foswosicl: The ‘following pBocecuse assume dhat eich sloment fn che wt element asoroy has ‘cl’ clegits where okigit 1 ig dhe covest orden legit cmd cligtt “a? lg the highest Over dlugit NAONNHOAKAHAAAAAES a, L) | Hidde RSSERERCCEEEEEEEEEEES Rac. sost (A.A) 1 for ic sted &- do use astable cost do sost Atuay A time comploxrty = ac¢m+e) - O(n) Sost the gwen eloment by Rakes sort. (dy 329 720 720 329 as7 aoe 329 aye 657 436 436 u36 839 > 457 y 839 > 4ST 436 657 ass 67 720 329 usT ass 720 839 6S7 839 Gi) M0, 46 48° 90 , gor (24,8 (70 170 ous 0G ee ors oor ogo Bor Ooy 80. > 602 s ous 3 ©2y O24 66 O02 o4¢ \7o 066 omg ols OG ©30 , 66 ©o2 O24 ous 266 O1¢ 990 \7o 802 PrPrEEFFEFFERN rrr Gy Cow SEA BAR BAR 5 EAR Cow oc 4 TAR DOG SEA DOG esa Ear Ruc BAR Row Row > EAR > OO > RY Cow

You might also like