Presentation is loading. Please wait.

Presentation is loading. Please wait.

Weight balance trees (Nievergelt & Reingold 73)

Similar presentations


Presentation on theme: "Weight balance trees (Nievergelt & Reingold 73)"— Presentation transcript:

1 Weight balance trees (Nievergelt & Reingold 73)

2 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) =

3 Weight balance trees - example
5/14 2/5

4 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 Updates Nodes on the path to the point where we update may go out of balance 2/5 5/14

6 Updates (Cont.) 5/14 6/14 2/5

7 Use rotations γ1 = ρ1 + ρ2 (1- ρ1) ρ1 y x γ2 = ρ1 + ρ2 (1- ρ1) ρ1
<===> 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)

8 And double rotations ρ1 z x <===> ρ2 A y x y ρ3 z D A B C D B C
γ1 = ρ1 + ρ3 ρ2 (1- ρ1) ρ1 z x <===> γ3 = 1 - ρ3 ρ2 ρ2 (1- ρ3) ρ2 A y γ2 = ρ1 + ρ3 ρ2 (1- ρ1) ρ1 x y ρ3 z D A B C D B C

9 The rebalancing lemma (Blum & Mehlhorn)
Let v be a node such that ρ(u)  (α, 1- α] for every descendant u of v ρ(v) < α and (insertion into right subtree of v) (deletion from the left subtree of v) or 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+ δ ) α]

10 We will not prove the rebalancing lemma, its technical, you are encouraged to look at the proof…
Here is what distinguishes BB(α) trees

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

12 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 insertion and b deletion happened through v since last rotation Then a insertions, b deletions v v ρ(v) w + b w + b - a ρ’(v) ≤ A’ B’ A B

13 ρ(v) w + b w – a + b α w + b w - a + b (1+δ)α ≤ ρ’(v) ≤ (1+δ)α (w - a + b) ≤ α w + b δα w ≤ (1+δ)α a + (1 - (1+δ)α ) b ≤ a + b

14 ( ) ) ( ) ( ( ) ( ) Divide the possible sizes of subtrees into groups
1 1-α ( ) 2 1 w1 = -- 1-α 1 1-α ( ) 2 1 1-α ( ) 3 w2 = -- …… 1 1-α ( ) i i+1 ( 1 ) wi = Node v is at level -- 1-α A node v is at level floor (log(1/1-α) s(v)) Maximum level is floor (log(1/1-α) m)

15 Let uℓ(v) be the # of updates that go through v when v is at level ℓ, ℓ-1, or ℓ+1
uℓ(v) = Total # of insertions and deletions in this subtree when s(v) is at level ℓ, ℓ-1, or ℓ+1 v Let rℓ(v) be the # of rotations around v when v is at level ℓ (when v has about wℓ descendants)

16 We show that c wℓ rℓ(v) ≤ uℓ(v)
If each update through v when v is at level ℓ, ℓ-1, or ℓ+1 is charged (1/c) then we can pay wℓ for each rotation at v when v is at level ℓ 7 8 Total charges per update are O(log n)

17 So why c wℓ rℓ(v) ≤ uℓ(v) ? If each update through v when v is at level ℓ, ℓ-1, or ℓ+1 is charged (1/c) then we can pay wℓ for each rotation at v when v is at level ℓ 7 8 Total charges per update are O(log n)


Download ppt "Weight balance trees (Nievergelt & Reingold 73)"

Similar presentations


Ads by Google