- , Implementation :( as extended BST ) weight Balance Overview : : Internal node : stores - splay trees - Given asetof keys - Static X={ Xo , Optimality . ,xn . , } More frequently accessed . . → splitter - and values . ( key key - → total j 'D keys closer to root float wt Ivo , . . .vn . , ) ⇒ weight - and weights . - balanced weight of ax xx Tv - two , entries in subtree . ,wn . , } , right -1 trees 1 $ . . . left - Assume : iesttiesataedwm . . . External Node : sorted syoaii.ea.awei.I.iq - sxn . , xosx ,s . . . ' key key , ④ positivity Wi > o . - probability pseudo : wi total weight ¥ 5 - Let : = Given Yeast ,aBsT - Let :pi=WiFw How to ( Nearly ) Achieve a - balanced if pseudo - prob is - Obs :& ? ; ! ! } } Shannon 's bound ⇒ discrete for all internal nodes p . - balanced . . . → Weight prob balance ( p ) sa distribution . tree : Perfectly balanced 9=42 Shannon 's Theorem : Ifpi { tathekastfropyipoiflgj ! P .in#alledT/balancelpg=maxlwtlp.lettl.wt-p.rightDa--4s :b reasonable → For each node p is : : Arbitrarily bad wtlp ) - total weight . of accessing Xi the prob =L 's subtree , of keys nip any Bst has expected search compromise wtlp ) .-wt .
- - ideal Ax Balance by Rebuilding ksb How to maintain balance ? Example :oi_ : key :%/I µµ /-% : utile an array Alo . Option 's . let ] Given : - Rotations : Similar to of external nodes : .is/ltnt4H3t2t4YJ.wsY6Ali3.wt . key AVL trees ( singles double ) Ali ] , Ali ) - value . Dm b - → BBK ) trees =3 . . - Rebuild subtrees : Similar t.buifralalo.zDR-buildtreelAG.is 'D - Assume Keys are sorted to scapegoat - Assume weights get > o return I . . $ 9 ⑤ . m . . - saetestrgetiteerigtodm.in#emi:neahTreesEmEt . ' weight Q ① - Balanced - based median : weight add a :O - K - D) i build Tree ( Alo ← Total wt - Let Ali ] .wt .az#:nne*/-Goal:Splitatosjskthal- = . iflk-tretvrna.co/x.basecase*loT--EiijAli3.wt ? jt ← o ¥ %÷tj , ] ' - Iii : - Letwin Iii A total weight 't - . - O ; Rwtsto ;Dm , IT " is "÷÷÷÷÷÷÷ Init : b=o ; Lwt - . . . . . . . . %fbfifgffemgyn.to ? j.iijjAmmi=D3 :* ¥ minimizes : ← Most balanced split - org Aj Amin - . t-T est - buildtreelacb.k.is ) !? CEi " R Q - A new Int Node ( Alb ] . key ,L,R ) #Esphthe return .it .
- , ⇐ Analysis Bad weight distributions ? Butitis pretty close ! : Does this algorithm produce - Ifa weight is very large the optimal tree Curt . expected relative to neighbors , Theorem :( Mehlhorn 'M ) rebalance maybe ineffective The above balanced split case search time ) ? algorithm produces a tree - ÷÷ ⇒ µ - The optimal BST can be " " d - No . search time is → whose exp . computed by dynamic programming t ⑧ SH -13 are ) weights Lemma : - entropy bound " ( not too much :c :* :* : nisig.EE ? a-n7w7 - . . says , where " H Lionizing , nice the . variation ) , inserts delete .tn :c - Jackhammer rebuilding . - → Checks Rebuild : . - * Ifnosuohp found Trees - when returning - ÷ ÷ from Great ! Tree is balanced Find : Same usual . Tree as : heights log%n,soO4ogn ) . : : Jackhammer ! recursive calls , update Else : ÷ time - guaranteed each node 's weight . . . 's subtree i - Traverse p ; . p.wt-p.left.wttp.right.int in order , store extern : : Insert Delete : Start same - starting at root , walk down nodes in array Alak - D i : as - Replace p 's subtree : search path standard BST . Stop at first i ! → After operation completes node pst ' with qq.gr ? er..-.s.ba1anoecp , > g÷9÷÷} ! I ¥ 7÷i i . checks rebuild buildtreeln ) " " " ° ,
- , when to rebuild ? Dictionary Operations : f÷÷÷÷÷÷÷÷i very heavy entries : 's weight an entry - If - find - when " backing out " is too high as usual , rebuilding : from insertldelete - insert : insert as usual is ineffective update node weights ynutbarlgniidnig , - Example but rebuild if needed - walk down search - delete doesn't help ! : delete as usual , path from root but rebuild if needed " :÷÷÷÷÷÷÷÷÷÷÷i÷ . ÷ - and - - balance : Every ( a. P ) : maxcpt For node p - ratio ( p )sp max max weightings internal node p is either 's subtree then : . - balanced . maxlp ) x on - exempt - Rebuild p - ratio ( pls p Max - : weight ( P ) - Traverse pisubtreeinorder For any set of Lemma : ' Given parameter Opal - collect external nodes in weighted entries , Jan , . anmodae.irsafioefsm.pt 't .fi ? idtreeunp--Y4 - remain : 'm ° ,
Recommend
More recommend