0% found this document useful (0 votes)
51 views31 pages

Unit 4 Notes

Data structure with c

Uploaded by

23wh1a05d7
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)
51 views31 pages

Unit 4 Notes

Data structure with c

Uploaded by

23wh1a05d7
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
UATT-G San Sune a! Batic tree concepls , Binary bree : Propertier , Repretentation oy Birra rece Ring OMOyE _ Pe le le Seosch tree, Binary Seas bree — fravreutaly Caractere), Csotror oy bray bree from braversals. Bese re Cota Deginrttion: A bree & a MON- Umeon data chuchu,e PELE LEAL EEE which item: Ole Mtanged tha Cotted «= SesMance » att ) uted to veprernr — Wtetaretiy Pelabiontiap exrebng Qnaonget Several dota tke me a ei ee] co mete lata feemt (nodes) Such that There U A Species dota ftom Called the R004 of bree - K Bnd th Semaining diols thems Qe partitiong into Numba Of omtutually exc lucive Ci.e., digjoter) i--t-td Subse each oy Ohh te Hsele a vee And tay ou Called Subtvees | Scanned with CamScanner “9 ~ ee we we ee we wy we ee the following Applications: — — Re presenting Prete Show, a — tree hrearchieal data Storm dat mm a enay that maker tt eatily y Searchable > Reprenntmy Sovted leet 9 deta, , p> As a OMKRF lod fox Composting align ens Tmoages ; for visual efpects : 1S Routing algowthms ' Meminseay i | ly Ancestorst The "0det that appear Gh the Path fom | ' the Soot %& A given moda ae the ancerto ' of the qiven mode ' 1% Branchett The Connectiont between element, 4 ‘ . S chfldeent The mocks Just belog a mocle - Decendanus ‘The Mocks that APpeag “Un ALL the POLAG From a giver Noda to leat Nock. Scanned with CamScanner — > in a PPept! The length 73 Edges & Connecting Une of 2 NOdet > Forest: A cet of tee ¢ Dele ef mode: The total mo. o Sub-Erees of a node > Degee tye: at a the Martmum degtee oj Nokes poth, Prom 200t node to thet nod. Aon oeo em wo Oo. a oj Zero HK moe ohisjome tvece U a -foreg, é ee Set of abt disjomt bveer ie, gub-treex leade to fotest : } > height: The Lengtn of longest path from that node ty § | tre leap mode « ‘6 > Intunal node + The Moder other than Oot Mode & leaver : > Level of trees the 20 node LW alecays Comeiclued otf —— i é tevcl 0, then lh Gdiaent Chfldwn Gu Supported t 6 be ok level fj Gnd Soen. : “> length: the Ungth of 9% pettreutar path a the mo of bwanches Ww thet Poth - ‘ > Leaver! There ate the etminal mode 07 0 tee obt'stinet 2 eth Succersive > patent node: The mec tehich it having => sibli one h list child ° model ate Conneckry by branches th the tree nodes of ‘ Nodeg Gh which ¢ futher Sub-tres! Same Parent . \ ‘Scanned with CamScanner ng CAE exmfrad NOde> A node which doetneg have Ord chite foe ov with degree Zero Cleat) | chil Lemna! ode: Noder forth at leat ome a tia riots » a tree har © Speedalty detegne 3 ee |. soot mode , Which th ghom cated tie tee of : level o a level 7 t level 2 } @ G—— level 3 Arcee! A, D7 ox ancettont of K Branches? Ap & a branch i CMidun: kK, L707 Ose Childean oy TF deteendent: 4,2, K,L,m ou etcenclantr of OD pak : Degtee 4 Nook: peqen oy Node A UK 8 ; Degtee o free! Degece of Above free UR Depth: The olepth of “Nook L Ku Fo . AE Bees 3, Leah, LD, WT KL, my ~ Scanned with CamScanner > height: The height op moot A & 4 D rntunad roles Ryo, p, Ft > level 0 bree: “the lev of ahow > length ; Fre A to m Length uw 3 au leaves 6 « ® Z € tree U 8 ¢ € ¢ > Leaver: £, 5,6, ,K, Lim ‘ ‘ Spee foe een 8G oe CA.p), (DT), CL) potent modes > paunt nodes: A,B,C, pip, 7 Ve J Mbtings: Roc au Sibley of D ' > terminal node! E, 3,6,4, Kt) aw terminal nodes au rien-bermined nods | ALB, OD, Fit > Non-teaminal nodes » ton-tenminal nodes | Pos teee 1 \ Sins Be F befimition! A bivtoay bree T U @ frnfe Set of Mody such thee > T & empty Cealled empty brary bree), ot > T Cortana Specialty desiqnetid ook called try Roo oc) ord te Bemaining Yiocke 9) 7 foem £0 dtsjomt binary heey T, and, (hth ay cole left Stb-tree And WyKt Gub-bee Bel pective, Scanned with CamScanner qesent bree! and o bemnty free Bee Hee beet Peart peer bray bree > KR Hee can omay be empty can have a bimay free, a node an e ; in be Cate of >a th chtfdsen Wheteat pextmum 9 too have an mum ber q 4 can a genus eee, & nocle childien - TyPet+ Then ase % tyres a brmasy trees * Full bengeg peas % Peyee Rinety bree * Compl broasy bree K Bima, Seach bse eee Ginety Bee? A bimasy kee ue a Pall brray tree ff 16 Contains = mianintum number “of mock it QU level, A bing fee of hate hk thet contisty o7 Wlaccémrung permet number 64 Cbtidten “te oll node te 2 | nod iu Cated a ful bimary tree ooo ® Scanned with CamScanner coriplate, binnay Beg 2 A bemany Eves binary tee if al i levelt except have ftv maximum =O. Mader pokte Ble (eH Eee) Geren | 1: fot lee, ot ft Seach fee & Biotasy fenecn tee A bimory totuich evety mode Contain & empy c& In Satish tre following Condition a tek * AU Feys wn the tess than key lege Sthtee GG te & tte weet ghould be + wight Subbe qy te jeihe Ken 2 tee 3 should be queata than key th the eoThe tape ard grt Subbwer oy te Woe ae agen bimasy Secech trees Scanned with CamScanner PeOPectes! a bimary bvec. hag — mumber a Propestiek © ar any bimary bree, maximum mo. a) “odig on (evel t 7 A wo 2 utero Loo 1 DY The omintimrum mo. of Meeks preci a brvtacy bre of heigue h ik bh ' ‘ 1@® Me heiyt 4 Complete brary bee etth 1 Mo. OF ‘ grocer uw log, (n+) © Fee ang non-empty brmary brea, Gh the 0. oF ear iat ociibec tiie 1iLMos a pemaae tere acl © re any men-em ply formasy bree T, TE nou the no. of teap nooks Cdegtee =0) ond M2 & tee MO 9 tnrtanal CA Pasort Oder (degtee = 2) then No=Mt!] O Told Yo. bimary freer porstbu tort mm Moder y C/net Me, Representation cf bimay freey Uting ease Ovilted Liste Bimasy bees Can be Aopweteded in any of tte onan : eo : > Wterg an ateay ( (rmene Representatvon ) FD Uhtmg a Linked Lee} (Uist ve presentatcomn) Vik Scanned with CamScanner Lament Sepreretaing 91 soasuy See* oes AL Bey Ae af rem K Thi Lype of vepwetentation & Static bey © oe “4 : oto f& AN awe’ Ub to he allocate bejor 9°) oe lin actual Wee in Ut : J le H Hew , the mocks oj the bree ae Stored tevel ba ed Starteg fem — Zeasth evel - i frast The wot ode 0 the bree tk toned in meomeny — lecatron of Allocated — yremoty ad te dectce the locatirn k the follow Yulu ce tee of any = Mecle m ones locatim D taten [foc Som n) a at node Mitty © Indien 1) the otsay wepresentation of the btmary tree ie ag Follows Scanned with CamScanner OO ee ae ie ag ma ga i > How f Fdentix the potent , the bepe child & wight child * Paunt(n): The parent of mode having tndex(n) FS nt ee Poor Cen be aie mot expat & 0 5 ode and has "Oo ap m=0 tan © the oot poser — oun OO 4! pasent “or A= floor (cn 12) = floor (@-1) (>) of loo (1) aie Johtid(nyh The tepe child 0] "Ode mum bend n ae at (2on*!) ex: dehtld (A) = jebtid (2) = e241 es eve wo be i ‘eenfid(n)® The onight chtid 1 de aed n & wee t (ont?) i E chtid CR) = Lobild GY eoxer2=6 Perf ext v cae ee Advantagest ZAHA | alas ibd, —— O pivee ace f any | monte gan be? posh and finding — the potent os Lett childuen of any por tretoy becauues! o}. the sandem “ adeed O Hea, data & ctoreel codthout mock ut fast ary pornty ‘be FB Succ etter 7° ancestry ; ee wi Yl ’ . a : [ [ 7 SD Progtannlag + tanguoge . which | otg ‘mote Suppet Vynaidic mencty | allocehom,, Use erly — this type o) -veprestntetisy we Scanned with CamScanner Se @ wstege gy memory : © Maximum depth yt fe fo be fred A i cient @ aasertiont L deltion a vee nod & pneggicl? 7 ‘ nivted, agpreertaticn Sl ony FES © peld x Eack neck aw Oo binary beee May have 2 ¢ noclet _e _ tiorlted a0 presentation op the brary '%e fee Or [lees i each fhild » Bo et cn ee ee ee Frets « Ceo 2 hot ho Childun, the corres ponding pot fields or NULL a ve prosntotion a dyynarnic : x thi type canned with CamScanner O No Wattage, of Memory Ocak ae oe fee eee O) gntetions & celehont fnvolwe me data movement lest except the Re ateange ment of — Pore’ Dis ad vantage! Pised vents O progiammng Languaget tonich do mot upped dina nic, moméy allocatron have olnfeieulty fra pts ren tang the — bimaty tee nn thu lyre 4 Be porverenbation . ee Ce © pomtu Frelole epae than just dat, fields. skewed Rens, S587 Th A nay tree eshich Contairy ef Chee lege child «& MyM Chil — Ehoveghouw the end & Called i gkewed binary bree 2 types ag Seeded brary ‘bees Thee axe ’ Dust Siewed berry bee FF vight Ckewed brary bee lect Stewed brnaty bee: A Stewed Ieimaty bree shiek hat only leet Sub tree i Called ag ler? Skewed binary Arey seprerentaton 4 at follows Scanned with CamScanner | bree tahich Diget Stewed hima bee: A gitewed bimasy , 7 et ‘ ood. Bintan, had only omgne Subbee called ag MGW Cle ved ras hee se @ Anmay depwerentation it a4 -Poltows a= S © 2 3 y 4 PEP PEE, OS. bie Seach, bres The Batic Opetattont = arr Can be performed on brary (earch bees Oe DS Ircertion Of NO > Peloton 6] & Nodle > Seaschg fee a postrertar node | > bravesel of 0 tree PROGRAM = 1% poo on fttert, deleti & Senech a node in a bimtasy Ceaseh node / Emde Chrct node 3 imt datos Struct nook flefe + Shuck raoda. Hight » us Peirce Jala ' Scanned with CamScanner Skeuch Mode FooL= NULL? Stuck Mode ¥getmode Come vi); Glruct Mole eae ve Prof}: ceouet mode bIntert (Chutt rode # rook, te data) 5 tnt Search (Shuck voce paoot , Int daa) s oid dvsplay (Struct sted 5 Struck Node amin (atneet ‘Broad wot) tort Vet = -1) fone 2H: , ect; Void enquene (Struct Mode tx) 4 votd deqenec)! Chuet vode ¥ getfant Ll); grad rode golel (Lhruct Node #7 void mac ) ty mt x) i Prt ch, n, Key, a5 do , porntf ("1 Anseet \E 9. geaeen") > poimep Coin Ent ue choice”) 5 seang (“7d beh) s : ‘Susiteh (ch) 3 . cate tt primbp ("iy Enta the element f& be imcedted) seant (“7d' 2n); Aook = ture Cet nm); Atsplay Croet) 7 break! Scanned with CamScanner 4 Core a: pronte(im Foutir the element ts be Searched): Geant (Yds keey) 5 it (Search Camot ,ey)==1) Parl Cord elamed & found” ey); ele print (7d element not fourd’, key); break |, default; pembf | trvoled option") 3 prmts Cl pest & continue"); scone (" ¥d"La) 5 qotilk (a 220; Struck mode Fgetnode Cink ) t styuet Node Atemps (chuct ved £) smaltoe (sigeoy (Struct mock)) ; temp > dala =n) . temp > lege = Noel ; emp 2g = NULL, gebun temp 3 Scanned with CamScanner ~_ an eo oem Chuck node fintet (Shut “ode #r0b, mE dota ) & Sef (vob = =Nuee) nook = getnods (dota); sotinn wook 5 4 cte Uf (data ¢=200¢ Ddofa.) Sool alee = insert Crook > leet, data Ys che ; : nook aE = poutert (L009 wignt_, dda) satuin 00k: es int Search (stud node wot, tt lata) Lf (Book == NULL) ; | sobun Of else ie (2008 > deta z= data) geben Uy (doka < woot > dota) ootusn Seasch Cacot 3 lar, datas elie | | else TF ; | | paban —Sesech Cao 3 wWgnt , cata)’ - canned with CamScanner ee co Void ditplay Cohuck mol # rot) £ Struck ode #temp + If (-A00t == Nove) £ Ponte (“mH tre a empty"): Debian ', y enqpeur Cxvot )' tohtle (front | >veax) z temp = gelfeonlC)! Pamte (yd ", temp Ddata)/I tf (Lemp 3 leet | =NucL) enqueue ( Cemp > leat) 5 H emp Sarge | =nutt) encyeue Lemp 2002 cea rcus C5 3 Void enqueue ( Shust woke #2) L wenn tt) Wreue PAeor] = 5 Ghrack mode Beler (Sfract 4 Noda €xvot , Mme n| 6 Struct node t-temp ¢ Wf (wooe ==NoLr) : Satiun A006 | : elie 1¢-(n yes NULL) fsee (2004) ; Aoot = NLL, 5 ele ip (0b bgt ==Nou) % temp = wots Qoot=~wotd wytd | “Free Ctemp)s a ole 1f (204 Songtd een. toymp = Foot 5 ‘woot = 00 D laje- yy Free emp) ~ Scanned with CamScanner . > > Dd > 3 » , » , , , , , , vrord deyunec 3} elte 2 fsa s vents (wood 3 pO? fron +S : / pool Ddobta «teh? a 4 7 Root Svigt= del (s008arrad Struct Mo c eX get font C) temp Sceta); 4 fmt me Paomt-+! 3 4 Aottun queue [ma]; valaan vot? , 4 efeucl nod. aaron (eteuck Ode Sree wot) UL UNgeet £2 SEARCH tp (aook = =NULLS Ent. ur chote | atin Of : : : waht le (Loot NULL enls the elament t be ireetid to C ae a doot = 2006 9 WHEL lo py | Cont pets om setiun 200+ 5 Le tnserr 2 SEARCH 2 enta wt chota | Emta a thwoe = Ge (tes GS io = free ' te tnt | t. INSERT L- SEARCH Enth Ww chole | i te Ome be Mie y io Ss 2 pres | te Continue | i, (eee | SEP ESt Ents wo chote err canned with CamScanner Ent th element te be lual Jo to € 2 3 prem ¢ to Contre / ( INséeT 2 SEARCH Enta wt Chola 1 Cita tw tlt t be nledid 16 feet 5 i pre t & Cmte 1 (. INSERT 2 SEARCH Enta ut chede 2 mtx tr elamént b& be ceotched. 9 3 clement ig found Pree | f° Comb 2 "Scanned with CamScanner Bimary earch tree travetinls (aecuuthe)+ Soe eee ee eee Me ches > A, bronentel ch. a, procese thal yrrstty LL the Modleg on the bree i; 7 Some a tee WU a mm Linear data Chucttuy ,» he 4 mo Untqte traversal <> linted Uc aur Evavemed from Pint fy [ost Seaprenctiatly > however, then i mo suey malinal mens atelr fos, the meds of a tee > Ther au 2 Hyper of bravetioh A Depth finct Gravenal kk Rreodtth fort bravenal ys tree om 3 atereune Cy pee oy leptin - tract avesents - K In kde bravertal — Vectr Che legt chéld, then. the posed Bo OA ahd nthe Faight chaflal : ke pre odt fravertal - Vistt the palont Ett ind te tepe and aight. child. * post Orda travernral- Vist lege cheld, “then the Webt cheld & then Posant Tnotohu faveual z the gnctde Gravel OF A Non-empty brary tree i ckeyined 94 > travene Che lept Lublyee in Luctwoley + > vist f \ HB? fs fe fhe, Root. noole : ‘i SS Travene Ue Tye SUbbree bh Scanned with CamScanner’ dng & @D BEA CHF Precder tonveual + The proveler braver! of a mon-emply binary bree U atjrmed ag > Visit te soot Node D> Travent te lee Gubtree tn Pre ctoler > Travere tte atgnt Subtree Pre ctcley st J PO po cher traversal t tm pol odu haveral of o “on-empby bertasy free "y deyimed as >Trovew the let Subbvee ur Post tole SS Teaver Ae Might cibtrer in port toy > visit Mw toot Nocle PH dda @DEGHECA Scanned with CamScanner >the & only ont Itind 0) bt ead ts fist — Frovethed K bevel - otcler Evaversal - Thet Hvovenal vicils Nodes boy bowels by bolle & farm leyl l fiom top right Feel —cholur Lroveual - The Level-ctcler Eravetsal of brnasy bee fravester thy modes tr a Level - by - level — mMonrer Prem top ba bottom Game leve, they OF bravesned ond Among the Mockt oj the prom (eye bo atl a Ubed fo Keep the dala Stricture Caled queue beach Of fae elements Yet. fo. be teavetteel « eet level ovals a ABe?D € FGd4 emt Find grad, precclir, port orl 1 Level ord 07 = Sree og) tf Se Snosder — 15, 21, 20) 35 140,42,51,66 466 notkhi'g . 7 eT Pred - 65, 21, 16) I bo, 30,86) 42, 60, 80, 10,92 tothe — 110, Pest 15) 35,30/42,40, 60/51, 21) 10) 92,80, 65 , 80, Level dey - 8S 127,99. 15,51, 92, bo ,60 30) YS, 3 Scanned with CamScanner Zz We PROGRAM [* Pryom & fom pla ment Elrod St, Sok mole dala 5 Struck node Peres Shut mode aright 2 499 provers ob a/ dd MOck OL, tt las.) | Stuck ode Brvet = NULL’ Stuck mode Rgeknods (int n); i giruck Nooke #ouert (Stu Bhud Mode £ quene [20]; Struct rode 4 getfont CV grt sean ot, Feenk= au ord erapene (Shuck node # ays vord dep C5 yond erecdth Catrick mode 4 soot) word peeordes (Struct 0d _ Pete); yoig modu (Shue “ack trol); yoid port ordas (Sthuct note # rool); york depth (Shut nod, $ret): void meine J = yk Gem Mas Scanned with Cams nner volo permtt (7 1 Irtet toe. Bee KH OFS"): perott Choy Enrter ce chotee" |: scant (1. d", &ch); Stoteh (ch) £ : cate te printf (in fritter tne element to be Masertecl') Scanp('7-d' an): wot = brceet (root, 5 breale ; coke 2: byeadth Cxvot)5 break’ cose $2 depth Croot); brean 5 default 1 printf C'm Invalid option”), 3 prnte (“pres ( te Cowtinue'!). Scant (*¥d', La): | white (a= % : shud mode ¥egetnode Cit ni) i Struct moot & Lemp = Cebuct node 9) wralloc Cora) (caret tock) Scanned with CamScanner Lemp > dolla =n} temp > Lib= NULLY, Eemp Dght = NULLS Beluaun Lemp 5 ) Strict rock. E tote Ctruek nook Pavol, me dotta & if (Soot == NOLL) | £ | wok = gebiiods Caate) ! Sehuen wool J & che tf (data <= soot >deta) root > leek = tet (aoot > leit , dob); che Apok J vight = Mek (Joot 3 nig , data), Setuin woot 5 | | | 4 Void breadth (shuit mock #004) £ Shuck mode Rtemp > it (aot = =Nuee) pant LW Tree. & Einpley "): Setirn 5 4 eAWeue Loot ys, Scanned with Camscanner , while ( front J = rear) ' § Lemp = get Prmt-()5 Print ("rd") temp D deta)! MC bemp > tat | = NULL) enqueue Clemp + let); Fe (Lemp Songnt { =NuLL) engeus (Lemp > alge) 5 dequeue) 5 B chuck mock Fget front C ) £ It ms Pronk ts Safun — quene Lr] 5 3 Votd enquene (Shuct rook # x) i Reon thy Aros [hear] = 7 3 Word denueved ) £ frat te) 5 Scanned with CamScanner void depth (stuct mode sf 200l-) £ pane (“in Preowla Travetal") Preovdes (200k) prt COM Inccoler qravenel")? ‘moreter (200 EY) iy: prime (h(n Pastors Taavenel J pestovele (Root) 5 Vord preovelr C&truct voce *s00t) z PF C800 ==NnvcL) Potuen J Pete (4d ", 2oot 5 lata): Preorder (woot + lot) ; Preorder ( X00b 3 wight) 4 4 i Vord mort C thuct node £2004) £ Uf (Aoot => NuLL) Aeturn 3 Inovde (20ot DUgt) 5 Pambe(* 7d") A00b > dada); ferotolr (400t > wight) 5 Scanned with cance Void potas ( rurt ror fonnt) £ Tf (-200f ==a0yer) Actin > postetde (Aoot 5 byt) 5 postorele, Ceoot 3 wy); ptt ("7d") root S data); {- Inset 2- BFS 2-DFE Era ts chore | Enta the cement & be tmuehd w pres | f& Cmtine | get 2. BFS 3.0FS Evin we Chota t genta th eharnent to be iMtetid 5 an t pron | t Continue | vauaae 9. @Ps 3-0FS Buta ys choty | wb iMtectid ebewnent be Is wna sl bras | f Untinu | t Quneat 2 BPS 3 OFS eula cheia emis the Clermmt = be terteg 03 Scanned with CamScanner fe tbh | 2. BRE 3. DFS Eta out thote 2 eo F if w 1. Dnt 1-BFs 8. DES ena ur chela 3 Prtordea Travetial io = Snowy Travenal S Pestova Troveuat 45 (3 Pres | t ttn 9& (is Pres lL to Cottnue | 13 (201s (slo Scanned with CamScanner Creatim Ke bmoy bree em travel © comida tre followmg Initia Evavertal ania «Rae a Ghiansy, Senn tree and eho fma ta Pret Pet Order - Iphovdul = S) 28, 29, 30/Ss, 25. Sey ae, 4Ors? ‘ © & ® OX, vuuvUuUvUUoUeoUUS ® @ D Pre — 38,29, 28,$)3% ew aa BE 8, WSR HST POE Sy SB, 33-80 24, 38,49 56,4, as bravertal £ Comthuct o brraty 38,85, 58,49 Pre— BS, 29,78, 5,30/33,42,3 > post - 9) 29,30/ following pre oven @ coma the ' Geanh tree and alo Fimd pe Im-ovde & port Orde ' pre kde — Bay by by Hy Ts lost 8 » () CO (3) Oo & 9) @ @ © Bre ordu — 1) 3) 6, 4-8, 10,18, 14 post — 1,4, 4,6.3, (3) Ue 10,8 Scanned with CamScanner ® courta the followng pott-ctolie “traveuay & Conshuct q 1 biemey. Geatch tyre ard alto Pind 14 Preevdu & trod Post eden — 2,8,9 516, US, 29, BB, BINT \ Sr 7 ©) 5) O Qo @ @ © @) Pree 13,¢,0 119,816, 38,29, 3, Beccles = fe 26S, 8,9, \1,16, 4, 29, 35,28 Scanned with CamScanner

You might also like