130 likes | 247 Views
Weight balance trees (Nievergelt & Reingold 73). Definition. A binary tree. Define the balance at an internal node v to be. where s(v) = #(leaf descendants of v). Tree T is of bounded balance α if for every v, α ≤ ρ (v) ≤ 1- α. ¼ < α ≤ 1- ( √ 2/2) = 0.2928.
E N D
Definition A binary tree. Define the balance at an internal node v to be where s(v) = #(leaf descendants of v) Tree T is of bounded balance α if for every v, α ≤ ρ(v) ≤ 1- α ¼ < α ≤ 1- (√2/2) = 0.2928..
Weight balance trees - example 5/14 2/5 ½ ⅔
Obvious properties The depth is O(log n) As we go from a node to a child the # of leaves under us decrease by a fraction smaller than (1-α) ≤ w ≤ (1-α) w
5/14 2/5 ½ ⅔ Updates Nodes on the path to the point where we update may go out of balance
Updates (Cont.) 5/14 6/14 ⅓ 2/5 ¾ ½ ⅔ ⅓ ½
ρ1 γ2 = ρ1 + ρ2 (1- ρ1) Use rotations γ1= ρ1 + ρ2 (1- ρ1) ρ1 y x <===> A ρ2 x C y B C A B a+b = ρ1 (a + b + c) + ρ2 (b + c) = ρ1 (a + b + c) + ρ2 ((a + b + c) - a) = ρ1 (a + b + c) + ρ2 ((a + b + c) - ρ1 (a + b + c) ) = (ρ1 + ρ2 (1- ρ1) ) (a + b + c)
ρ1 γ2 = ρ1 + ρ3ρ2 (1- ρ1) ρ2 (1- ρ3) γ3 = 1 - ρ3ρ2 And double rotations γ1= ρ1 + ρ3ρ2 (1- ρ1) ρ1 z x <===> ρ2 A y x y ρ3 z D A B C D C B
(insertion into right subtree of v) or • (deletion from the left subtree of v) The rebalancing lemma (Blum & Mehlhorn) • Let v be a node such that • ρ(u) (α, 1- α] for every descendant u of v • ρ(v) < α and Let ρ2 be the balance of vr There are constants d (α, 1- α] and δ (> 0 if α < 1- (√2/2) ) such that • If ρ2 ≤ d a rotation rebalances the tree, i.e. γ1, γ2 ((1+ δ )α, 1- (1+ δ )α] • If ρ2 > d a double rotation rebalances the tree, i.e. γ1, γ2 , γ3 ((1+ δ )α, 1- (1+ δ )α]
We will not prove the rebalancing lemma, its technical, you are encouraged to look at the proof… Here is what distinguishes BB(α) trees
What is special about BB(α) trees ? Thm: Suppose we carry out a sequence of m updates on a tree of size at most n at any time (starting for the empty tree). Then even if a rotation at a node v takes O(s(v)) time, the total cost of all rotations over the sequence is O( m log n)). Proof.
ρ(v) w + b w + b - a Let w = s(v) when a rotation occurs at v (v goes out of balance) We show that the number of updates through v since the last rotation v was involved in, is at least δαw Suppose ρ(v) ≤ α Assume a insertions and b deletions happened through v since last rotation Then a insertions, b deletions v v ρ’(v) ≤ A B B’ A’
≤ ρ(v) w + b α w + b w – a + b w - a + b ρ’(v) ≤ (1+δ)α≤ (1+δ)α (w - a + b) ≤ α w + b δα w ≤ (1+δ)αa + (1 - (1+δ)α ) b ≤ a + b