Lect13 Weight Bal Slides

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

- ,

weight Balance : Overview :


Implementation :( as extended BST)
-

Given asetof keys


-

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 .
,
-

Assume : left right

iesttiesataedwm syoaii.ea.awei.I.iq
. . . .

xosx ,s . . . -

sxn sorted External Node :


.

key key
'

④ positivity
> o
Wi ,

pseudo -

probability :

Let
-
: =

wi total weight ¥5
Given Yeast ,aBsT
-

Let :pi=WiFw pseudo prob -


How to (
Nearly) Achieve is a balanced if
-

Obs discrete Shannon 's bound for all internal nodes p


:& ? ; ! ! } }
-

.
. . .

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_
:

Given an array Alo


of external nodes :
. .
let ] Option's
-
:

Rotations Similar to :
utile
key

.is/ltnt4H3t2t4YJ.wsY6Ali3.wt
Ali] key Dm Ali) value AVL trees (
singles double)
b
. -

, .

. .
-

→ BBK ) trees =3

Assume Keys are sorted -

Rebuild subtrees Similar : t.buifralalo.zDR-buildtreelAG.is'D


weights to
scapegoat
get
Assume > o return
I
-
.

$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-

-

- = . -

Iii : Iii?jt←o¥%÷tj iflk-tretvrna.co/x.basecase*l


A oT--EiijAli3't.wt
'

Letwin .
-

,]
weight total
Rwtsto;Dm IT

is"÷÷÷÷÷÷÷
.
Init : b=o ; Lwt -
-
O;
,

..
.
.
.

"
..

%fbfifgf emgyn.to?j.i j Ammi=D3


minimizes :
¥:*
Amin Aj Most balanced split
org
-
-

.

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
""

whose exp search time is



.
-

No .
BST can

computed by dynamic programming


SH -13
t⑧ Lemma : weights are
)
the:c.tn:c:*:*: nisig.EE?a-n7w7
- . .

says ,
where H bound much
" "

( not too
entropy

Lionizing
-
. nice

variation) inserts delete ,

,
rebuilding Jackhammer
-

Trees .
-

Checks Rebuild : .
-
*
Ifnosuohp found -

÷ ÷
Find from Great ! Tree is balanced
Same usual Tree when
returning
:
as -

:
.

heights log%n,soO4ogn ) Jackhammer !


:

.
: recursive calls update .

÷
Else :
,
. .

time
guaranteed
-

i each node 's


weight ;
-

Traverse
p
's subtree
: p.wt-p.left.wttp.right.int : in order, store extern
InsertDelete : Start same as
:
i -

starting at root walk down ,


: nodes in
array
Alak D -

standard BST
i
search path Stop at first Replace 's subtree
! p
-

completes
'

After operation 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 : :

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:
-

but rebuild if needed path from root


"

÷ :÷÷÷÷÷÷÷÷÷÷÷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

Max ratio ( pls -

p exempt
-
-

Rebuild p :
(
-

)
weight P
Lemma : For set of
'

Traverse pisubtreeinorder
any
Given parameter Opal , weighted entries ,
Jan -

collect external nodes in .

anmodae.irsafioefsm.pt
't

°
.fi?idtreeunp--Y4
,
remain : 'm
-

You might also like