Docsity

Trees and graphs in c, Summaries of Computer science

Partial preview of the text

Download Trees and graphs in c and more Summaries Computer science in PDF only on Docsity!

wr. range of applications. A tree data s UNIT - V sequential order popular non-line defined as follows..- data is organized in der. A tree is a very tructure can be iat In linear data structure ata is organized in random or Tree is a non-linear data structure which organizes data jn hierarchic recursive definition. follows... which is organized i A tree data structure can also be defined as Tree data structure is a collection of data (Node) recursively ual element is called as Node. Node ina In tree data structure, every individ lar element and link to stores the actual data of that particu Ina tree data structure, if we have N number of nodes the: of links. Example / ©O © Terminology Ina tree data structure, we use the following terminology 1. Root Ina tree data structure, the first n can say that the root no root node. We never have multiple root nodes in a tree n hierarchical st next element in hierar’ n we can have 2 maxi @. a Ss TREE with 11 nodes and 10 edges ode is called as Root Node E ry t hi a roo node W : - . Every tree mus ave e de is the origin. of the tree data structure. In any tree, there must be otiby ar 1€ |] structure and this js a yucture tree data structure chical structure. mum of N-1 number Here ‘A’ is the ‘root’ node 2. Edge In a take data structure, the Connecting link between any two nodes is called as EDGE. Ina tree with 'N' number of nodes there will be a maximum of 'N-1' number of edges. @. “Edge x © 3. Parent Ina tree data structure, the node which isa predecessor of any node is called as PARENT NODE. In simple words, the node which has a branch from it to any other node is called a parent node. Parent node can also be defined as "The node which has child / children". @ nA ee N\ Here A, B, C, E & Gare Parent nodes © / @ 4. Child sae oatmeal i: Oe . ‘ sim; le € be Structure, the node which has atleast one child is called as INTERNAL Doge ple words, an internal node is a node with atleast one child. . Ina tree data structure, nodes other than leaf nodes are called as Internal Nodes. The root node is also said to be Internal Node i d ; if the tree has h 1 nodes are also called as Non-Terminal' nodes more than one node. Interna ® fom Se * foany © ‘Here A,B,C, E& Gare Internal nodes icf wf -~ Every non-i © as ‘Internal x 8. Degree Ina tree data structure, the total number of children ofa node is called as DEGREE of that Node. In simple words, the Degree of a node is total number of children it has. The highest degree ofa node among all the nodes in a tree is called as 'Degree of Tree’ (A) Here Degree of Bis 3 “ ON Here Degree of Ais 2 (C) Here Degree of Fis © . yer PR) GS QOS So © Ina tree data structure, the root node is said to be at Level 0 and the children of root node are at Level 1 and the children of the nodes which are at Level 1 will be at Level 2 and so on... In simple in a tree each step from top to bottom is called as a Level and the Level count starts with '0' words, and incremented by one at each level (Step). Level 0 Level 1 oO Ne JN /- ©) @ ©) © ) Level 2 / d © a) Level 3 10. Height Ina tree data structure, the total number of edges from leaf node to a particular node in the longest ight of the root node is said to be height of the path is called as HEIGHT of that Node. Ina tree, he tree. Ina tree, height of all leaf nodes is '0'. @) Here Height of tree is 3 ae ran ©) © © gf \ Height is 0 OO Ov . frany tree, ‘Height of Node’ is = from leat total number of Edge oath, f to that nede in lenges © (4) . In any tree, ‘Height of Tree’ is the height of the root nade. 11. Depth Ina tree data structure, the total number of egdes from root node to a particular node is called as DEPTH of that Node. In a tree, the total number of edges from root node to a leaf node in the longest path is said to be Depth of the tree. In simple words, the highest depth of any leaf node ina tree is said to be depth of that tree. Ina tree, depth of the root node is '0'. in | Booaty fret’ , | A Laasy tree 16 & Specel +ype of yee L-Sttet wonich every © nose Can have ee eM rplden, om 18 tron 8 icf bill § iQ nao) ngrt child de m7 bioaty Yee) every ' k ch 0 site oY | childrok. 0% 7 chy Idnody. 4 fi i than 2 chednoekhy Different types of beowy 7 ee Is Shicly Binary q¥ee ( Full Binary Tree ) a Complete Binary tree. 2. pervect Biren Tyee ab Skewedl Binaty Tree H- Balanced Binary ie |: Strichy Birary Tyee ( Full Bang Tree ) KK 7 J Gn have A ta O BNOy tyee, Every Node -hre 7 hich bincwy , Maxime, 4 Awo Chil dven. Rt 1m 8 sake J : oy NOC, " children & very mode Showld hae geaclly ie That yneary every folermal de muah hove Exactly ‘two childen. Strictly Biravy Tyee dita Shocturg ned to Yeprescot —matnenrorhtal Ex preauron4 = | ®) ® @ @ 9 as ghee SN 6 (A+B) aC. ined to Expravon tree: TE ig a binasy “Thee f an avitnmatic Exporenion. | — L node Contain on san 4 (num bey / varrably) 2 * — nr / podes Contain operatog like +, 7, ’ x Uses * — E \ = Expsemion Svaluahey pc ; Ceres py ; 4; - CoHyves a © (AtB) a. of, po he pr Sy Su Dre ts FL eer Re ee - Totereal Propectics Af hei bk = h ten -folal rody 2 2 Leapmoces . > H+ Saved Binary Tree ( Degenevol- pees ) “A Skewek binary Wee of birowy alc nodg, ra ye chid , asda ertney lefror rahe Fbrevieg a Straight Jane. yee whe a) | ft skewed Binary Tee 6 ol der Above ite & tft Skeaed. Binary Tree, =o have left child “ode only: b) Right eked Bidary “TCC “ © ARove Nee e Rion Skewes Binary Tree , au rater nal nodes hove gt child wde. ooh. OTK, Kew oe Propectiy Bioavy TeeeQ w) fy teed, Binoy Tec 9) aA tsee Ta) conch eachnock. har at matt og -childvem C refer chile rgpt ce) Haio pepe eg }. Hata noda ok lalel § > 2 Levelo 4 ge f nod! Levelt 7 gi 24 vode4 Hi nth ar) = a a ci el height fox nN wots (RE ene prec.) ankey 2 Jog, (» AENO ; Flop (or ed Satoh ° Ede tan binaty Tree pin ~ nodes > ao 6. la saa nm emp) binary Tyee Nog leofirades No ¢f nock, ory Ochi ldeedih tfey
    ani Baa Weed US Dy y j Tek E rr = > Ty aveoy vepeesotaten q binowy yee, : UAE ont deenerbrocut (i) ow —to repre binary prec. “ @) = Level a | FA We ret o3 oS 4 ‘ Level ws ¥ @) Q ~—* ano pros? “— 4 / / oa os E G Leied sa $ \ a v2? pevella a ’ @) @ © ad os cy on SPP S| : yout rok 18 aloays Stoved f- index © : Ley chikode — Shove ot meat, Righh child node Stored x (') ; & at Codex Qt é 2 ja} Bic © else [>i a]-| ECHL mo o 1 2 3 of ¢ 18 % @ ? itp leFEchi ld 3p node 8 Stowd at index {tren will be Atovedl = AMEE Right chil node sfosedlat Jetta overwdgtion) E> p ye ppesenh bina ny tree of cepin 9 unt onsen ye wed one dh | sneered YS Ox dosh maa ws I mae - — Sn Dre u Pl Dootncn Exacoph Fos Expowxion Ieee : a a +B Cc _> thigh prieiy frst * C yaluale Bec ’r. — an Add pe are ey Th + pecan rain opoa € Ewer (A-%) / (cre) Hu (8) ecorth _ 0 el operat oh) oad . \: _ |e sep So | be CoS, Yweot- Stepa Left Sud ae dr oe mS CWA ¢ ( eB) oy hid / Reg hk Sb &eprar— > sep: Bg Pa © © Cae —dtcorts Regn child Ww zB : Brinn 7, ( Search I¥ee (B54) Tig & special typed] binciss ts a Yee Tn @ Broary Searen tec, etre vale Fi | feo. ynust be Sevalles nox) the povest yok, aod tne Value g v ght nok roust be quale +nan ay h +O 4 parent “node, the . vyule iS applet yecurs y > tie left & * ge Sabbreed of soot” 1 en- 30 718) de & 4° and Tan- ov di assy yoot no Tame apove ry ; ube ~ \ex Pr + a all coded i ne . kd ae ne sobtye A fro ne woot wade and a Greate a sock V0 “the "a A te iQ BS) (Bicat Search +8ee ) ] ve change node (3 -» (3) ; me oun} ; omsist C OCT Seer \et-o "er 5 lA; 43, mA, ot we aa oa ma , 7 ( Ay ith ¢ ) sore NS é cel BSE aD 4 (