0% found this document useful (0 votes)
88 views9 pages

DSA Unit-4

Uploaded by

omchaudhari7559
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)
88 views9 pages

DSA Unit-4

Uploaded by

omchaudhari7559
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/ 9
DSA UNIT-TT SEARCH TREES SYMBOL TABLE: + Symbol able is an imporkant data structure ct i 0 cated & maint 6 compilers in order to store intormation about she occurrence ained id entities (variables, functions , Objects , classes) - * + compiler stores Ane identifvers of an phe prog: in the symbo) table. sthe identifiers are stored in the form of name, value, address 4 type- e Thus, compiler can Keep track of QU the identifiers with all the Necessary information. Global syrnbol Table =» C4” be accessed by — au the procedures & value _\var_fint scope symbol table Pro.one |proc| int Pro-two | proc] int |, pro.one symbol table / \ pro-two symbol table one-4 | var | int jot | var | int| one-2 | var | int 4uyo-2| var | int one-5 | var} Int ywo-5| var | ink / \_ [one war | int one | var | int +wo-3 | var | int [one -4| var | int [one=1 | vor | int} ywo-4 | var| int inner scope £ tnner scope 2 inner scope 3 + Types of symbol fable? rP i) static symbol table > stores fixed amount of inygmatie (OBS ts i 3 stores dynamic inpormation. Y 3 Dynamic Syenbo! table iy i eo (AvL) coding) Advantages OH, using Symbol. {ees ° ie hi operations = ~ Fast 100K up of (dentifrers duting compilation. ear e the Tuntime allocation for identifiers is managed Insertion wsing symbol tables - Handles issues like scope of identifiers & implicit atdarations. Deletion Séarching * WEIGHT- BALANCE TREE: (wB8T) = WET is a BST whose balance is based on the sizes a the subtrets in each node. = OPTIMAL BINARY SEARCH TREE: (08ST) “Tne element having more probability of appearance should be placed nearer to the root pst & the element whtth appears for \eaat number Mes it Lesser probability should be laud awa om ane rock * 4 i q e + ye ts & OST that minienizes the expected search cost - (no: m comparisons required to search yor a given Key) « + Time complexity for searching a key = > OBST 1S constructed yom rlid) — jesource LT) > the value oy Je destination. yoat — weight C(i,j) = ne {cUik-s) + e(Kd)y + w(i,j) Cost c(ii) = 0 vi) =0 w(ii) = Ui) wij) = eG) + 4G) + (i, 5-4) Your | ‘2 Wor= 12 ]wy3= 4 ee neh 2 \or= 14 [Oye 2 y 7 (a, 02,03 ,44) = (Ao, i6, int while) . ! a y= 1) etd) = G30) 3 ere fe i q (0:4) = (25,04) Noss 2 [tye 2 ) (it) 4 \Coy= 32 oy? @) Gb (3) Con) root X DYNAMIC PROGRAMMING + (oBsT) : pane prog 5 method in which the sol? +0 a problem is obtained by maxing sequence of aecislons - i * Dynamic programming works on the prindple % optimality . Solve problems - “Tt Is typically applied 40 optimization problems. “The principle optimality states that "tn an optimal sequence choices , each stbsequence are also be optimal. % + QBAT Th OBST, we always celece the value % K whith © obtained from minimum art (while @nstuetton) , thus fe follows principle Oy optimality - + OBST is. an CKAMPIE A, dynamic programming: , < problems thar Can be Solved bY dynarmme prog! = wmputing nh Fibonace’ number - = wmpulng binomial wey: ~ warshall’s & Floyd's algorithm . 7 OBST: X WEVGAT BALANCE TREE! > AVL TREE* A binar +The FE dynamically watanced Aree to be proposed - Retrieval of any node = [ottegn)] “TT fs O non-empty BT with TL & Tr the (ett & right subtrees, qnen Tis height valanced if & only if: i) TL & Te are oF same heigt: 4) pifference % In height of Te 4 TR chouldh'é be mor than 6A ont. it; (Potance factor = (1,0, Balance - Heignt of —_ Height oF Factor (eft subtree right subhree BE) * neght of \taf node =0- Y tree structure that is balanced with respect to height of subtrees. AVL TREE OPERATIONS : ANL TREE OPERATIONS 1) Insertion 2) deletion 3) Searching ROTATIONS OF AVL TREE FOR REBALANCING: (LL, RR, LR RL) i) eft Rotation (tt) : = every Mode Moves One position to (@tt trom the current Position. ~ Single rotation . = Right unbaraned tree- 3) veet- Right Rotation (12) : Every node moves one position to (tft, then one position to the vight from current positron. - Pouble rotation. INSERTION ALGORITHM: ) tnsert a new node as new leaf just 3) Trace tne path from n encountered» cheek TE herghts a) 5 6) otherwise restructure by new node towards root. yor a lefe(a) 4 right(n) differ by atmos 1. es, move towards parent (n). doing Uther single or double rotation. 2) Right Rotation (RR) - - every node moves one position to Fight from ine current position. ~ single vot ation - for lett unbalanced tree- 4) Right -Leet Rotation (RL) « 2 tery nodt moves one positton to Fight , then one position to left “wom antrent postion. - Double rotation. as in srdinary BST- tach node 'n’ DELETION ALGORITHM’ i) search the node to be deleted - Jal YH tsa leat node then simply mare fe NULL. nor then the node must 9 4] swapped with its inorder successor - 3) Now traverse back up the path 4owards root checking the Br o, Lach node & performing the rotations auordingly . SEARCHING ALGORITHM + h tek the aaa be searched be ‘key. 2) ¢ Key root then go to the reght Subfrte. ; make that node as ‘current node H neitha cheated Key ==Yoot 3) Gmpdaie key with ourrent node & follow stp @ - X RED-BLACK TREE: (RB-tte) “Tt is G@ tYPE of BST r balandng a ree using dhe colour attribute ~The rook node ts always black- ae (0) =the ettrnal nodes are black . = Two consecatlve red nodes are not allowed . «x children of red nodes 3 black. & ( ©) possible parent o, red node > black. = umber of black modes should be same @) ©) in a path pom root node to external node- = All (eat nodes have the same black depth: od > INSERTION I RB TREE” i) reryrm insertion oy 4 node ‘%! same Uke QST- 2) Newly added node x! (5 red. is Yoot node then change it to black, ay *! 4) 3} newly inserted node is red 4 its parent & qlso red, then ba is needed. tanung 5) a parent of new node ts ved then check the colour of uncle. a) JE uncle = black or NULL, then do rotation & veeo recolour. red then: recolour both (uncle & parent) & 6 uncle = 7 tis not root node then recolour it 4 o check IF grandparent necheck - 6) in RB-Hee balancing iS done by + Tecolouring & voratton. P= parent = unde ge grand parent x= new cild. AN TREE: AA tree is created gro the tdta of RB tree, but contains fewer fotations 4 less cormplex- ~ Time complexity for operations o AA Aree i ~ Lev node (instead o wlor) is used jor balanuing node =black, level iS one less than parent level node = rtd, level Is samt OA parent level. Properties * Devery node can be either red or black. 2) root node (s Always black - 3) Externa) nodes are black. &) Every, path yrom root to Weak node has same nov oF WACK nodea. 5) x, node Is Ta then child must be black. 6) Leet child may nok be red. > _while conversion [yom RB-bee to AA tree, no- oL levels reducer . whenever red node omes, wnnect it Horizontally to the parent hodt on the parent node's leva. ~4give arrows. INSERTION® i) The nodes are inserted similar to gsT- ) J parent £ its child ane on the same level then porzontal tinks ane possible: 3) There ane rome ramdtons in Horizontal links + Horizonta) links G-D-@ © ® (eet horizontal Two consecutive v links are not right links ae @ allowed Nof allowed 6d ® @ apply. split Operation operation A single right rotation when an = A cing lett retation when insertim insertion Creates horizontal link: untatds two horizontal inky ~may Ureate onseuarve mgt = Causes level a, middle node to be increased by ant. horizontal links - X KDIMENSIONAL TREE (KD tree) ~ used for 0 anizing some no OK points in a space with K-dimensions. ~ Ie is pasically % QsT weh constraints - = points are arranged in a space called K~ dienensiona space: = he points left side tm the space represent the (ctt suble 4 ih the réght repraene Mgnt sulbbree- — kK > dimensions. ey TTT ey tre (36), (15), (it5) , rl?) QD 1), (10,9) \ a wmpart the x-value at this (evel y > wMpart y-Value at this level. Applications of Aad KD tree: i) Nearest neighbour search 2) vatabase queries - * SPLAY TREE? A stl€-balancing BST with no explidt balance condition. ~ Recently accessed elementl can be accessed quickly - - A special operation “splaying" (3 performed on splay tree = splaying ? arranging tne elements in a tree in such @ YAY that fine mare “recently accessed node will be placed as root node. cases of spaying: © m 2iq-2aq cast: @® 2i9-2ig sep * @ 2g steP: = UR SHRP ; - Ww skp -LSHP - nae access ¢ @ ® s re ae franiparent | (P) ©) 3) ©) (i) © @® ® 2 66 ‘ Q | i ® ® ) © © © ® ® ‘ oe Ofte ® (4) © © | aaroot Pa tight O} 00 x. P3 right a © 4° right % P | | | | | aigetefe | zag = rgnt | O 0,2,4,6, 813,01 (splay aree) © © > gg » Pp © @, (@) @) (6)

You might also like