Presentation is loading. Please wait.

Presentation is loading. Please wait.

Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location 

Similar presentations


Presentation on theme: "Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location "— Presentation transcript:

1 Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location  range in value for ceil(log (N+1)) to N What affects height of BST?  sensitive to order of data in which you insert or delete items. Solution: Maintain balance by using variation of BST.

2 Splay Trees Type of balanced binary search trees. Search, insert, delete, and split have amortized complexity O(log n) & actual complexity O(n). Actual and amortized complexity of join is O(1). Priority queue and double-ended priority queue versions outperform heaps over a sequence of operations. Two varieties.  Bottom up.  Top down.

3 Top-Down Splay Trees On the way down the tree, split the tree into the binary search trees S (small elements) and B (big elements).  Similar to split operation in an unbalanced binary search tree.  However, a rotation is done whenever an LL or RR move is made.  Move down 2 levels at a time, except (possibly) in the end when a one level move is made. When the splay node is reached, S, B, and the subtree rooted at the splay node are combined into a single binary search tree.

4 Split A Binary Search Tree B e d bA a B c C D f m g E S

5 A a B d b B c C D f m g E e S

6 b A a B B d c C D f m g E e S

7 b A a B c C B d D f m g E e S

8 b A a B c C B d D f m g E e S

9 b A a B c C B d D f m g E e S

10 b A a B c C B d D f m g E e S

11 Two-Level Moves e d bA a B c C D f m g E Let m be the splay node. RL move from A to C. RR move from C to E. L move from E to m.

12 RL Move B e d b A a B c C D f m g E S

13 b A a B B d c C D f m g E e S

14 RR Move b A a B B d c C D f m g E e S

15 b A a B B dc C D f m g E e S

16 L Move b A a B B dc C D f m g E e S

17 b A a B B dc C D f m g E e S

18 Wrap Up b A a B B dc C D f m g E e S

19 b A a B B dc C D f m g E e S

20 b A a B dc C D f m g E e

21 YouTube lecture CS 61B Lecture 34: Splay Trees

22 Java Applets http://www.ibr.cs.tu- bs.de/courses/ss98/audii/applets/BST/SplayT ree-Example.htmlhttp://www.ibr.cs.tu- bs.de/courses/ss98/audii/applets/BST/SplayT ree-Example.html http://techunix.technion.ac.il/~itai/


Download ppt "Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location "

Similar presentations


Ads by Google