✓ I auotitsesisbtrieeasrdisewarbsss .%:÷pn Er AVL Height Balance Balance factor : BSTNoderotateRightlpstnodepyballvt-hg.tl - hgtlv - for each node v. the heights v. right ) . left ) Dstnodeg =p . left 3 " tree that satisfies this return g ④ ④ ⑥ condition 1 - ⑨ ④ " Tree A ooestnwimboaosmeeis . ?÷÷÷÷÷÷÷÷i7n& itowto maintain them property ? ' . " " ⑤ AULT I % . ⑧ E rotation ⑥ µ , Worst cases : height :h= ? % guard Acbscicdst Acb seeds E , An AVL tree of Theorem : § nodes 20 : y z iz n= , z . . . height h has atleast Feng - I J 5 8 nil 3 13 21 - z . . - : hmm . . An AVL tree with nodes n nodes Fo - 0,5=1 , Faster . ,tFa , corollary Recall : : . has height Ollogn ) . ohh ) in AVL Proof :( Induct conjecture , of nodes Min no : Fact : Faa 9455 where tree of height his nth )=1=F h=0 Proof : - I , -1 ten , " - firs )/z h=l n(h7=2=Fy - I " " Golden ratio : y . n÷e÷ loan . ' nm :÷i÷:::÷÷ , . ' Khaitan ) -1=1%51 = Ollogn ) A D , n , \ /
" AVLN ode rebalance ( AVL Node p ) - Double rotations I !÷÷÷÷÷÷÷¥÷÷÷÷÷¥:÷" null ) return p iflp ' right .feft ⇒ : ③ ight left ifcbalancefactorlpls - l ) ② -, ⑤ ' ② JO go ⑥ ② ⑤ Is - , ⑤ iflhtlp.IE/-t.lett)s=htCp.letturight ) ) ' → ② n ⑤ Bestrode rotate left-Right ( BsTNodep ) j - - - AVLNodeinsertlkeyx.ua/uev,AVkNodep)l - rotate Left ( p iflp.nu/l)p=newAvLNodelx,v ) . left ) . left I ::÷i÷÷÷÷ ( return rotate Right ( p ) p :÷÷÷÷g÷÷¥ionsM i i i , . . . . else iflxcp . key ) , ⑤ autre : met " us :¥i minims :i :# Basting .tw :c :p :* : 't ? Utilities : MA Find int height ( Avlnodep ) : Same as BIT return { . - l - right heavy P==n " " Insert : same as Bst but as Barz Left ( → : " rebalance ' ' back out . height . . - p o .w I . we void update height ( Avlnodep ) ' ④ How to rebalance ? Bats -2 - left heavy ' p.height-ftmaxfheightlp.lt ) , intbaianaractorcauh.SI?p;risht " Left Ep Ag ④ ¥ ④ ④ return heightlp ( . right ) - - - height ( plett ) . . . . ① . . . " >
- y : Balance factor -2 m Deletion : Basic plan Example 4 : cases - left heavy , " - Apply standard Bst deletion Left ② ⑤ ④ \ s :* : :* :÷¥ :O . ÷÷÷ ⑨ ?÷÷ " sina.me :# cement - . - rebalance Example ? ⑧ Left : detente - right heavy ) - z ! ! , ⑤ " . - ⑤ 1 i i i :÷ .is?::::i:::mM : ✓ " . , . → maris . - o I ④ ° ① ④ Example NWo amdeelaetse.lk#g.e1YenodeP ' am ④ ④ ' - ( " return rebalance ( p ) * examples otateteigh F- ti + in - I i ^
Recommend
More recommend