Lect13 Weight Bal Slides
Lect13 Weight Bal Slides
Lect13 Weight Bal Slides
splay trees -
Static
stores'D
X={ Xo Internal node
,xn , } Optimality :
accessed
. . .
,
.
(
-
and values -
More
frequently key key
float wt
→
splitter
closer to root → total
Ivo ,
. . .
.vn .
,
) keys j
-
and
weights weight -
balanced weight of ax xx
Tv two } in subtree
trees
-1
entries
1$
-
,
. . . .
,wn .
,
-
iesttiesataedwm syoaii.ea.awei.I.iq
. . . .
xosx ,s . . . -
key key
'
④ positivity
> o
Wi ,
pseudo -
probability :
Let
-
: =
wi total weight ¥5
Given Yeast ,aBsT
-
.
. . .
prob Weight -
balanced balance ( ) sa
p
distribution
→
.
tree
9=42
Perfectly balanced
{ tathekastfropyipoiflgj!P.in#alledT/balancelpg=maxlwtlp.let l.wt-p.rightDa--4s
Shannon 's Theorem :
Ifpi is → For each node p :
:
the prob .
of
accessing search
Xi , wtlp) total-
weight =L :
Arbitrarily bad
Bst has expected of nip 's
keys subtree
any
:b reasonable
wtlp ) compromise
.-wt .
- -
ideal
Ax How to ksb
Balance by Rebuilding maintain balance ? Example
:
:%/Iµµ/-%
:oi_
:
Rotations Similar to :
utile
key
.is/ltnt4H3t2t4YJ.wsY6Ali3.wt
Ali] key Dm Ali) value AVL trees (
singles double)
b
. -
, .
. .
-
→ BBK ) trees =3
$9
.
⑤ .
m.
saetestrgetiteerigtodm.in#emi:neahTreesEmEt
.
weight -
based median :
'
weight -
Balanced Q①
-
add a :O
Let Ali] .wt Total wt build Tree ( Alo K D) i
.az#:nne*/-Goal:Splitatosjskthal-
←
-
- = . -
Letwin .
-
,]
weight total
Rwtsto;Dm IT
is"÷÷÷÷÷÷÷
.
Init : b=o ; Lwt -
-
O;
,
..
.
.
.
"
..
t-Test !?CEi
"
Q R
-
-
buildtreelacb.k.is)
A return new Int Node ( Alb] key ,L,R )
#Esphthe .
. i t
.
- ,
⇐
Butitis pretty close ! Analysis : Bad weight distributions ?
Ifa weight is
Does this algorithm produce -
very large
Theorem :( Mehlhorn 'M ) the optimal tree Curt .
expected relative to neighbors ,
The above balanced split case search time ) ? rebalance maybe ineffective
algorithm produces a tree
÷÷ µ-
be - d
The optimal
""
No .
BST can
says ,
where H bound much
" "
( not too
entropy
Lionizing
-
. nice
,
rebuilding Jackhammer
-
Trees .
-
→
Checks Rebuild : .
-
*
Ifnosuohp found -
÷ ÷
Find from Great ! Tree is balanced
Same usual Tree when
returning
:
as -
:
.
.
: recursive calls update .
÷
Else :
,
. .
time
guaranteed
-
Traverse
p
's subtree
: p.wt-p.left.wttp.right.int : in order, store extern
InsertDelete : Start same as
:
i -
standard BST
i
search path Stop at first Replace 's subtree
! p
-
completes
'
qq.gr?er..-.s.ba1anoecp g÷9÷÷}!I¥7÷i
→
i .
buildtreeln)
, >
°
,
- ,
when to rebuild ?
Dictionary Operations
f÷ ÷ ÷ ÷ i
very heavy entries : :
If an
entry 's weight
-
"
backing
"
is too
high rebuilding
,
-
find :
as usual -
when out
is ineffective -
insert insert as usual
: from insertldelete ,
Example ynutbarlghelp
niidnig !
but rebuild if needed update
walk down
node
weights
search
, doesn't -
delete delete as usual:
-
÷ :÷÷÷÷÷÷÷÷÷÷÷i÷ .
( a. P ) balance
-
and -
For node p :
maxcpt
-
:
Every max -
ratio (p )sp
subtree internal node either
.
max
weightings's p is then : .
maxlp ) x -
balanced on
p exempt
-
-
Rebuild p :
(
-
)
weight P
Lemma : For set of
'
Traverse pisubtreeinorder
any
Given parameter Opal , weighted entries ,
Jan -
anmodae.irsafioefsm.pt
't
°
.fi?idtreeunp--Y4
,
remain : 'm
-