1 / 16

Weight balance trees (Nievergelt & Reingold 1973)

Weight balance trees (Nievergelt & Reingold 1973). Weight-balanced trees. (WBTs) (Nievergelt & Reingold, 1972) are binary search trees, which can be used to implement finite sets and finite maps (associative arrays).

benniem
Download Presentation

Weight balance trees (Nievergelt & Reingold 1973)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Weight balance trees(Nievergelt & Reingold 1973)

  2. Weight-balanced trees • (WBTs) (Nievergelt & Reingold, 1972) are binary search • trees, which can be used to implement finite sets and finite maps (associative arrays)

  3. A weight-balanced tree (WBT) is a binary search tree, whose balance is based on the sizes of the subtrees in each node. Although purely functional implementations on a variant WBT algorithm are widely used in functional programming languages, many existing implementations do not maintain balance after deletion in some cases. • The difficulty lies in choosing a valid pair of rotation parameters: one for standard balance and the other for choosing single or double rotation.

  4. A weight-balanced tree (WBT) is a binary search tree, whose balance is based on the sizes of the subtrees in each node. Although purely functional implementations on a variant WBT algorithm are widely used in functional programming languages, many existing implementations do not maintain balance after deletion in some cases. The difficulty lies in choosing a valid pair of rotation parameters: one for standard balance and the other for choosing single or double rotation. This paper identifies the exact valid range of the rotation parameters for insertion and deletion in the original WBT algorithm where one and only one integer solution exists. Soundness of the range is proved using a proof assistant Coq. Completeness is proved using effective algorithms generating counterexample trees. For two specific parameter pairs, we also proved in Coq that set operations also maintain balance. Since the difference between the original WBT and the variant WBT is small, it is easy to change the existing buggy implementations based on the variant WBT to the certified original WBT with a rational solution.

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

  6. Weight balance trees - example 5/14 2/5 ½ ⅔

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

  8. 5/14 2/5 ½ ⅔ Updates Nodes on the path to the point where we update may go out of balance

  9. Updates (Cont.) 5/14 6/14 ⅓ 2/5 ¾ ½ ⅔ ⅓ ½

  10. ρ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)

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

  12. (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+ δ )α]

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

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

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

  16. ρ(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

More Related