0% found this document useful (0 votes)
23 views13 pages

HW 3 Part 2

home work cse 582
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)
23 views13 pages

HW 3 Part 2

home work cse 582
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/ 13
() \ 2 Time (omplenity | TON) = On) : as Eat node is visited one , thre time Conspleaiby Sums tO O(n), Whe DIS hoof nodey Visualizahion : les take Crample 6% a bree I . 75 ° ae, FuncHon Returns — Eaplanatim cau COUNTN opEs) 6 t+ (rtrto4+o) +Ul4l4o) + CounmNenes 3 It (lt 0+ 0+ (t4040) ar PP? Counrnopes + leaf node, vetimng a @ 39 counrwooes + leak Node, wetuone 1 co > CountNopey) 2 It) #Cit0 40) > Coumrnopet(e) L Leaf hode returns 4 Steps: ven howe decke wethe, Gore node jf Hm MULL A not , (Fit (Sweturn 0 2: Then Reairnvely Count tre nod-y in the WeFE and vier subtoees IS RB. tren Add 4 ( tov the rent node) bo sum te lett and right Counts # Ak last We veturn total] Count Of nodey spedhe ingtances: if the has no nedy ‘ey Cru) phen fan Immediately returng’y ' ©) count LEAP nodes same eraneple as before FunenowlAle Returns Explanat'on COUN TLEAFNODES 2 o 426 | ca) > COUNTLERE wopEs a l4 | (2) 95 Count Leen OE, / leat hode retuynes (ce 22 CUNT LEAF WOE ' Leafrode, vetya - cs) > COUNT LERE RES. | ei Q) 2 QUNTLEAEWopE 4 ts) time complenity as €ath Node I's visited One, te Lime Covplen H i¢ TLn)= Oln) wle nis no-of tadey Steps descripth™ * 1 Oneede wretere arvuk pode i nuw, oF + AS deckeab) Yeturn 0) 1F both lett Erisnt CLalayen ave null ten yeturn a z= RZ gvelg Counk ee Feat nodes initre! ep E and xlyrt cubtrecs 2 Retin tre total count of leat node ak lage: SpedHe inctanuy if theve Ts only voot Al ithe it hes ne childyer it vets ‘4’ 4. FIND HEIGHT. Function call Retims > Explanation FINDHEIQHt 1) 2 (+ marti, 1) > FInd HEIGHT OD | 37 BND HEIGHT) ° D> FIND HElauT ds) 0 END HEIGHT Y) | t+ mar lo) Leat node , veterons 0 lef he ty vets 0 (4 man leyo) 44> FIND HEIGH( A) Q ipa node , velurn 0 Time Complent rg. TO”) = oln) *4 Cath node tS visited onto Steps dacipton teotr the current nodeCury) is null; retin ne) 2+ Rewwslevly Calumlate the Nergnt of tng lest and wight cubtreey 3: Take The manimum of tne leb i and right hejgnb and add 4 4 Return the total height OF he bee, speitie inttances Whtn fmae hay no nodey CL one node. veh ome Non-— leat moddy = 3 C1,2,3) TCH) = o ln) a4 Same 2am node I's Vistved ONCE Steps WD Dexpipti'en + } if the Gurvent node (Cum) I's nul or a teak, vetuyno 2° Reuvsively Count hen-leaf node in tre left and Ty he gubbecy 3. Add 4 © tre Sum of lepe and ri'gnt oun tt. 4 Return the total’ Count ee pe) He gy. Speutfie Ins tances iF bree nay only one rode whitn is rook Huy He funidon returns o ) 1s BinarysearcH TREE 1S BINARYSERRLUTREE (Soa = |S BnaeycemeenreEe ( 3,-10, 5)-» ae LE isenuaeyscrecmtece Cuil) | bee a s Senne cement quate /\ 'SQINARY stave cure ee 6,50) 3 a 158MM copy alge 2 — violahin (95) pay Li'snt subtree must be. IN, tre range of (sjo) 94 aisy belww 5 they trees bot valid: Conspleni ty Anal ysis Th)=0(n) 2] As Eath node 15 visited gnu validate Steps Descri ptron - bre the wayrdt nude Ceury) is nul, ¥ thorn bu RTF The Made 'Vqle V6 ont of Yange, raotum false . B Recs Vly Leele ty MefE cufote wit, an updaled manimunm Valuc - + Reaurivty eck te ait Subtte wil OO tedeed ii, val SPeu'Hie Instanty ; ‘ all Dhetamus where atts vroleadcs binary we Property Cir tn’ Bay he hode Vale left Suv Wo vy abe (-2,™) vesul k Mh da with Subir. oy var 7 bekenud trey #) (5 BINARY SHHECH TREE (4, 1,0 ,0) stu la 'SBINABYS tapCure cE (819) -0,39 9 be 'SBINARY ceacure EE CAI 15) = bree 310) > falte S810) 2 false EINARY SeARcaT REE (Ay 1/10;-0) Pfalte IS BINARY StpRCH+e EE Cay L Winagy s FORO tee (A, Is time ve Corplening Oln) a pas to visit: £0 nodes ae ONCE Step Dercripl'y if the Indew Vento dy of the array $I yveturn tree a fp the value AF Ai] ts out oF Yang, return false Reunsively chou te left tld ab index oe : Rewmtive ly cute tee Ve Cl ee 2vitg. Spedne Dvstomus when entred orMmay Teprtsentalim ts nok of BST Ae LSB, He loe27d The vale 2 appears in wrong locot™ fy tee ony iolait yg te BsT wk. 2| 3 Diagram 4) ie | Zs 10 a 7s Te eS ee cl Stab Prom Gore lo, the algor(hy wr'll teaver Je leFE thregh to ty S and Finally to LY wri te minim Mord e: Complexity Analysis OCP) whens bh is the nei of tree Shepaon step Descrip tary if the wor node Is null, the functons oa nut, {ndicatiry thap cine tree's Cay ty Tf the tefl Ould of the care node I's hull SE means tok the uvy Node Jtrelf yy toe mininwm Ky in tree Fh othe left Gal is nob Ny te funeh'™ vecusievly calle itself on te lett cnild Cus lett) proving down tHe ter unt) Ve fin» he ter bmost node - te Sie Inttanay tr aor entUl) jthen returt nui fF ULyyY pomh toa node with no Cuildy the furtte corvelly yetud ho Single =e but jf tte Code calling t's funch’on doy nok cieuc IF the yetrrtd bode i's nok hull fEcow ld lead +9 acley Cros. s) te iN 10 20 GS 1X g 2D oe / 4 lees Saige wank print all elements in thevange [0; 28) stoabing from Sinw® to £IFS 220 we print ISS. Move to Hy left Uild tv STN 10 2 oz. we print Ip. Move to Pee she Child 10, one. lod Lr We Print |r Meve ty oiste wold ot (TO wl 2» te 10 £28 We print 26 SEE Complou ty vy Anal ysrs Oty ie ems te ne CN oes, ak (kt nas ty visit eath node ONG: Step by step Pnalusis 3th the Unmw node's null) te reumm ond Indicaty thre art no nody to proce Dt the Curve node key is greek trey & we need t cece the leFE Suboe ay trervt may be ly within ange la;bJ Dif the Unrvent node key within te vange [Lapty: we Prine tha 2 if pete ce node's Key te ley Han l | we employe’ ie aiyt tule po Keung Hatin fo witdy he range a Speed tic iInthantss aici No clemadd In We voerer Zo a CALS. PELINTELEMENCINEANG E iw ay (si0)) Rew : Mo output sinw then Ane : RORY Ty Te range aur S a) Diagram : \ os 7 3 - iN! Vey T's arxsy follows wuh-heap propeahy Covey Parent Vode « IL, Uuldren. Compleat ty Analuy 5 00h) becare we eck internal node Ona Speelhic Instanuy Emphy array ox root elentronly : Auto Woah cay Povey witn ott equal Serain heeap demenk. 8) aerey & = Clo, 3/507 ,157 2/17) 2), 23 lt fiwttel Min-heop 3 fs 10,5) Prouming Remains elemen HY * ALG] =7 Creplan 3) * Heap becomy (5/107) ne ALSI='S Cola 5) : Heap becomy Pato) Alby =20 (replaur) Heap becomes Cio, 201s ACa] = 1 Creplaee) Heap becomes Lis, 26, ty] ey Arata | oll) Proums remely dently uae ae Tvatoncsy tc=l Stwply wetuyn Con Rebevn te enb rt Sovted avvay le> Invalid fp ak es ah bus s7,y bal eo | cs - oS Was 7 tir We 2 Staxt from te woo E Citys) add bo wre It Move to ddldytn 3c0 7, Se5 5 yy, | Added SDP erplovirg fyranty : 41476 SURE Raydt: L13,55 ae “a Cowslerniky, Analy tls OCM) Whe m fst no of Clemenly LE Speelal Cary All elements 2K Rebuy He entise hoop No eclemamH £K Retuyn an tmp hy U'st Sinsle rllemene, oe VE the root Le yeturn re, Otherois ©, return empty.

You might also like