Presentation is loading. Please wait.

Presentation is loading. Please wait.

11/20/2016IT 2791 Is this an AVL tree?

Similar presentations


Presentation on theme: "11/20/2016IT 2791 Is this an AVL tree?"— Presentation transcript:

1 11/20/2016IT 2791 Is this an AVL tree? 20 30 25 8 1735 23 22 19 1 5 74 3 14 12 13 0 15 11 1827 26 28 32 3438 36 37 40 29

2 11/20/2016IT 2792 20 30 25 8 1735 23 22 191 5 7 4 3 14 12 13 015 11 1827 26 28 32 3438 36 37 40 29 9 9 2 -2

3 11/20/2016IT 2793 20 30 25 8 1735 23 22 191 5 7 4 3 14 12 13 0 15 111827 26 28 32 3438 36 37 40 29 9 1 the worst case

4 11/20/2016IT 2794 Analysis BST Average Heights on n Random Keys 1. 2. Devroye and Reed,, SIAM J. Comput. ‘95 the worst case n nodes n

5 11/20/2016IT 2795 30 40 10 20 n=4 10203040 20103040 20301040 4!=24 20 30 10 40 20 3010 40 30 10 20 30 40 10 20 probability??? 4  p 4 3  p 3 2  p 2 = 0

6 11/20/2016IT 2796 Forget about the probability 4  p = ?? 3  q = ?? (4+3)/2 = 3.5  Amortized Analysis p and q are the probabilities to have a BST of height 4 and 3, respectively. Amortized Analysis simplifies the average-case analysis by ignoring the probability.

7 11/20/2016IT 2797 Some data-structures are not suitable for Amortized Analysis E.g., AVL, BST. Why? Q: Given an n-node binary search tree, what is the time complexity of search m keys in the tree? in the worst case AVL : BST : 1. The worst case of AVL is already tightly bounded to a good behavior. 2. The worst case of BST is not acceptable and hence supporting information regarding the statistic properties of the data space should not be ignored. This is why:

8 11/20/2016IT 2798 Splay Trees: Splay out the data along the path of access A good data structure for Amortized Analysis In Splay Tress, although there does exist some bad operations, but there is no bad sequence of operations. Thus, we don’t have to worry about the probability of any particular bad operation, because it won’t inflame the cost in a sequence of bad operations.

9 11/20/2016IT 2799 Splay Trees: More dynamic Since there is bad operation and we do not allow such a bad operation to form a bad sequence of operations, the tree must be adjusted not only during its construction phase, but also during every the accessing operation. In that sense, the Splay tree is “more” dynamic than the AVL tree and the BST

10 11/20/2016IT 27910 Splay Trees: Strategy Move the referred node up to the root along the path by the following two rotations: 1) zig-zag and 2) zig-zig G P X BC D A zig-zag GP X BC D A

11 11/20/2016IT 27911 Splay Trees: Strategy G P X B C D A zig-zig G P X B C D A See Fig 49 – Fig 58 for an example of splaying nodes.


Download ppt "11/20/2016IT 2791 Is this an AVL tree?"

Similar presentations


Ads by Google