Rank-Balanced Trees Siddhartha Sen, Princeton University WADS 2009 Joint work with Bernhard Haeupler and Robert E. Tarjan 1.

Slides:



Advertisements
Similar presentations
Chapter 13. Red-Black Trees
Advertisements

Balanced Search Trees Robert Tarjan, Princeton University & HP Labs
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
1 AVL Trees (10.2) CSE 2011 Winter April 2015.
AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
AVL Trees CS II – Fall /8/2010. Announcements HW#2 is posted – Uses AVL Trees, so you have to implement an AVL Tree class. Most of the code is provided.
Rank-Pairing Heaps Robert Tarjan, Princeton University & HP Labs Joint work with Bernhard Haeupler and Siddhartha Sen, ESA
CS202 - Fundamental Structures of Computer Science II
CSE332: Data Abstractions Lecture 7: AVL Trees Tyler Robison Summer
AVL-Trees (Part 1) COMP171. AVL Trees / Slide 2 * Data, a set of elements * Data structure, a structured set of elements, linear, tree, graph, … * Linear:
Tirgul 5 AVL trees.
CSC311: Data Structures 1 Chapter 10: Search Trees Objectives: Binary Search Trees: Search, update, and implementation AVL Trees: Properties and maintenance.
Chapter 6: Transform and Conquer Trees, Red-Black Trees The Design and Analysis of Algorithms.
AVL-Trees (Part 1: Single Rotations) Lecture COMP171 Fall 2006.
Rank-Pairing Heaps Bernhard Haeupler, Siddhartha Sen, and Robert Tarjan, ESA
Dynamic Set AVL, RB Trees G.Kamberova, Algorithms Dynamic Set ADT Balanced Trees Gerda Kamberova Department of Computer Science Hofstra University.
Self-Balancing Search Trees Chapter 11. Chapter 11: Self-Balancing Search Trees2 Chapter Objectives To understand the impact that balance has on the performance.
Fall 2007CS 2251 Self-Balancing Search Trees Chapter 9.
Self-Balancing Search Trees Chapter 11. Chapter Objectives  To understand the impact that balance has on the performance of binary search trees  To.
Tirgul 5 This tirgul is about AVL trees. You will implement this in prog-ex2, so pay attention... BTW - prog-ex2 is on the web. Start working on it!
AVL Trees v z. 2 AVL Tree Definition AVL trees are balanced. An AVL Tree is a binary search tree such that for every internal node v of T, the.
Balanced Search Trees CS 3110 Fall Some Search Structures Sorted Arrays –Advantages Search in O(log n) time (binary search) –Disadvantages Need.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
New Balanced Search Trees Siddhartha Sen Princeton University Joint work with Bernhard Haeupler and Robert E. Tarjan.
Balancing Binary Search Trees. Balanced Binary Search Trees A BST is perfectly balanced if, for every node, the difference between the number of nodes.
CSCE 3110 Data Structures & Algorithm Analysis AVL Trees Reading: Chap. 4, Weiss.
1 Balanced Trees There are several ways to define balance Examples: –Force the subtrees of each node to have almost equal heights –Place upper and lower.
Search Trees. Binary Search Tree (§10.1) A binary search tree is a binary tree storing keys (or key-element pairs) at its internal nodes and satisfying.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
CS 253: Algorithms Chapter 13 Balanced Binary Search Trees (Balanced BST) AVL Trees.
Fall 2006 CSC311: Data Structures 1 Chapter 10: Search Trees Objectives: Binary Search Trees: Search, update, and implementation AVL Trees: Properties.
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
Oct 26, 2001CSE 373, Autumn A Forest of Trees Binary search trees: simple. –good on average: O(log n) –bad in the worst case: O(n) AVL trees: more.
© 2004 Goodrich, Tamassia Trees
Data Structures AVL Trees.
Balanced Binary Search Trees
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees Linda Shapiro Winter 2015.
Binary Search Trees1 Chapter 3, Sections 1 and 2: Binary Search Trees AVL Trees   
AVL Trees AVL (Adel`son-Vel`skii and Landis) tree = – A BST – With the property: For every node, the heights of the left and right subtrees differ at most.
Balancing Binary Search Trees. Balanced Binary Search Trees A BST is perfectly balanced if, for every node, the difference between the number of nodes.
CSE332: Data Abstractions Lecture 7: AVL Trees
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
Search Trees.
AVL Trees 6/25/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Balancing Binary Search Trees
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
Red-Black Trees 9/12/ :44 AM AVL Trees v z AVL Trees.
AVL Trees "The voyage of discovery is not in seeking new landscapes but in having new eyes. " - Marcel Proust.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
AVL Trees 4/29/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Data Structures Lecture 4 AVL and WAVL Trees Haim Kaplan and Uri Zwick
Red-Black Trees 11/13/2018 2:07 AM AVL Trees v z AVL Trees.
AVL Trees CENG 213 Data Structures.
CS202 - Fundamental Structures of Computer Science II
Red-Black Trees 11/26/2018 3:42 PM AVL Trees v z AVL Trees.
CS202 - Fundamental Structures of Computer Science II
v z Chapter 10 AVL Trees Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
CSE373: Data Structures & Algorithms Lecture 5: AVL Trees
Copyright © Aiman Hanna All rights reserved
CS202 - Fundamental Structures of Computer Science II
Red-Black Trees 2/24/ :17 AM AVL Trees v z AVL Trees.
Richard Anderson Spring 2016
Red-Black Trees 5/19/2019 6:39 AM AVL Trees v z AVL Trees.
1 Lecture 13 CS2013.
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
CS210- Lecture 20 July 19, 2005 Agenda Multiway Search Trees 2-4 Trees
CS210- Lecture 19 July 18, 2005 Agenda AVL trees Restructuring Trees
Presentation transcript:

Rank-Balanced Trees Siddhartha Sen, Princeton University WADS 2009 Joint work with Bernhard Haeupler and Robert E. Tarjan 1

Observation Computer science is (still) a young field. We often settle for the first (good) solution. It may not be the best: the design space is rich. 2

3 Research Agenda For fundamental problems, systematically explore the design space to find the best solutions, seeking elegance: “ a quality of neatness and ingenious simplicity in the solution of a problem (especially in science or mathematics).”  wordnet.princeton.edu/perl/webwn Keep the design simple, allow complexity in the analysis.

4 Searching: Dictionary Problem Maintain a set of items, so that Access: find a given item Insert: add a new item Delete: remove an item are efficient. Assumption: items are totally ordered, so that binary comparison is possible

Binary Search Tree Symmetric order < > e ci agn k Why not hashing? 5

6 Binary Search Tree Access k e ci agn k > > <

7 Binary Search Tree Insert h e ci agn k > h < >

8 Binary Search Tree Delete i e ci agn kh m Find successor Swap i k Delete k

Problem: imbalance How to bound the height? Maintain local balance condition, rebalance after insert or delete balanced tree Restructure after each access self-adjusting tree Store balance information in nodes, guarantee O(log n) height After (during) insert/delete, restore balance bottom-up (top-down): Update balance information Restructure along access path a b c d e f 9

10 Restructuring primitive: (Single) Rotation Preserves symmetric order Changes heights Takes O(1) time y x AB C x y BC A right left

11 Known Balanced Trees AVL trees (“passé” according to one author) weight balanced trees 2,3 trees B trees red-black trees etc. Goal: small height, little rebalancing, simple algorithms not binary

12 Ranks Each node has an integer rank, a proxy for height Convention: leaves have rank 0, missing nodes have rank -1 rank of tree = rank of root rank difference of a child = rank of parent - rank of child i-child: node of rank difference i i,j-node: children have rank differences i and j

13 Example of a rank-balanced tree e ci agn kh If all rank differences are positive, rank  height

14 Rank Rules AVL trees: every node is a 1,1- or 1,2-node Rank-balanced trees: every node is a 1,1-, 1,2-, or 2,2-node (rank differences are 1 or 2) Red-black trees: all rank differences are 0 or 1, no 0-child is the parent of another All need one balance bit per node.

15 Height bounds n k = minimum n for rank k AVL trees: n 0 = 1, n 1 = 2, n k = n k-1 + n k-2 + 1, n k = F k n k = F k+3 - 1, F k+2 <  k  k  log  n  1.44lg n Rank-balanced trees: n 0 = 1, n 1 = 2, n k = 2n k-2, n k = 2  k/2   k  2lg n Same bound for red-black trees

16 b Insert bInsert c 0 c 1 a Insert a > > 1 0 Rotate left at b 0 1 Insertion example Demote a Promote a Promote b

17 > e d 2 Insert e c b > Insert d a 1 > Rotate left at d 12 Insertion example Insert c Demote c Promote c Promote b Promote d

e d b a c 2 Insertion example Insert eInsert f > > > f Rotate left at d Demote b Promote e Promote d

19 1 Insert f f 1 1 e d b 2 Insertion example a c

20 Rebalancing: insertion Non-terminal 0, 1, or 2 rotations O(log n) rank changes No 2,2 nodes = AVL trees  log  n height!

def e Delete aDelete fDelete d 1 Swap with successor Delete 1 f 1 d b 2 Deletion example a c Double rotate at c Double promote c Demote b Double demote e

22 e c b Delete f Deletion example

23 Rebalancing: deletion Non-terminal 0, 1, or 2 rotations O(log n) rank changes

24 Amortized (time-averaged) analysis If t i is the actual time of operation i and  i is the potential of the data structure after operation i, the amortized time of operation i is

25 Non-terminal cases Must decrease potential!

Insertions: 1,1-node  1,2-node Deletions: 2,2-node  1,1- or 1,2-node  = #1,1-nodes + 2  #2,2-nodes non-terminating steps are free, last insertion step: Δ   2, last deletion step: Δ   3 If there are m inserts and d deletes (n = m - d), the number of rebalancing steps is O(m + d) 26

27 Rank-Balanced Trees height  2lg n  2 rotations per rebalancing O(1) amortized rebalancing time Red-Black Trees height  2lg n  3 rotations per rebalancing O(1) amortized rebalancing time Yes.No. Are rank-balanced trees better?

Better height bound? Sequential Insertions: rank-balancedred-black height = lg n (best)height = 2lg n (worst) Theorem. The height of a rank-balanced tree is at most log  m. Degrades gracefully from AVL trees as d/m  1 28

29 Proof Give a node a count of 1 when it is inserted Total amount of count in tree is m Potential of a node = total count in its subtree When a node is deleted, its count is added to its parent if it has one Let  k be the minimum potential of a node of rank k Claim:  k satisfies  0 = 1,  1 = 2,  k = 1 +  k-1 +  k-2 for k > 1  m  F k   k

30 Proof of Claim  k = 1 +  k-1 +  k-2 for k > 1 Easy for 1,1- and 1,2-nodes Harder for 2,2-nodes (created by deletions) But counts are inherited

Rebalancing frequency How high does rebalancing propagate? O(m + d) rebalancing steps total, which implies  O((m + d) / k) insertions/deletions at rank k Actually, we can show: Theorem. There are O((m + d) / 2 k/3 ) rebalancing steps at rank k. 31

32 Proof Use an exponential potential: 1,1- and 2,2-nodes of rank i get potential b i 1,2-nodes of rank i get potential b i-2 where b = 2 1/3 The potential change in the non-terminal steps telescopes. Combine this effect with initialization and terminal step.

Telescoping potential … … bibi b i-1 - b i+1 b i - b i+2 b i+1 - b i+3 b i  = -b i+3

34 Fix k. Cut off growth in potential at rank k: 1,1- and 2,2-nodes of rank i: b min{i,k-3} 1,2-nodes of rank i: b min{i-2,k-3} Then a rebalancing that propagates to rank k or above decreases the potential by b k-3. The same idea works for red-black trees (we think).

Preliminary evaluation 35 TestNXRed-black treesRank-balanced trees # rots  10 6 # bals  10 6 avg. pLen max. pLen # rots  10 6 # bals  10 6 avg. pLen max. pLen id queue_id work_set_id zipf_id dyn_zipf_id

Preliminary evaluation 36 TestNXRed-black treesRank-balanced trees # rots  10 6 # bals  10 6 avg. pLen max. pLen # rots  10 6 # bals  10 6 avg. pLen max. pLen id queue_id work_set_id zipf_id dyn_zipf_id

Preliminary evaluation 37 TestNXRed-black treesRank-balanced trees # rots  10 6 # bals  10 6 avg. pLen max. pLen # rots  10 6 # bals  10 6 avg. pLen max. pLen id queue_id work_set_id zipf_id dyn_zipf_id

Preliminary evaluation 38 TestNXRed-black treesRank-balanced trees # rots  10 6 # bals  10 6 avg. pLen max. pLen # rots  10 6 # bals  10 6 avg. pLen max. pLen id queue_id work_set_id zipf_id dyn_zipf_id

Conclusion Rank-balanced trees are a relaxation of AVL trees with behavior at least as good as red-black trees and better in important ways. Especially the height bound of min{2lg n, log  m} Exponential potential functions yield new insights into the efficiency of rebalancing. We anticipate more applications. 39

For insertions, yes. But what about deletions? Deletion rebalancing is complicated, ignored by textbooks, and many database systems do not do it So, can we avoid deletion rebalancing? Yes. Relaxation of AVL trees, ravl trees, achieves log  m access time using lglg m + 1 balance bits … and no rebalancing during deletion! Is rebalancing necessary? 40

41 Thank you

42 Extra slides