1 / 31

What is the benefit of using BST?

What is the benefit of using BST?. N=30. Search 17, 29, 3. 19. 10. 28. 4. 14. 23. 35. 1. 7. 12. 17. 26. 32. 21. 37. 0. 3. 5. 11. 13. 15. 18. 20. 22. 25. 27. 30. 34. 36. 38. log 2 30 = 5. O(log 2 n). What is the real benefit of using BST?. Search 18, 2, 26.

cid
Télécharger la présentation

What is the benefit of using BST?

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. What is the benefit of using BST? N=30 Search 17, 29, 3 19 10 28 4 14 23 35 1 7 12 17 26 32 21 37 0 3 5 11 13 15 18 20 22 25 27 30 34 36 38 log230 = 5 ITK 275

  2. O(log2n) What is the real benefit of using BST? Search 18, 2, 26 20 10 30 1 17 25 35 0 5 14 19 28 34 38 23 4 7 12 15 18 22 27 32 36 3 11 13 21 26 37 ITK 275

  3. What is the benefit of using BST? The average height of a binary search tree of n nodes is O(log2n) if the n nodes are arrived based on a uniform distribution on the space of possible keys. This is as good as the binary search. Proof: skip f(n) : The average internal path length of an n-node BST ITK 275

  4. The average height of a BST : O(log2n) f(n) : The average internal path length of an n-node BST f(3) : (3+2+3) / 3 = 2.67 0 0 1 1 1 1 2 2 0+1+1=2 0+1+2=3 0+1+2=3 ITK 275

  5. The sequence of node insertion will affect the shape of the BST 1 Highly unbalanced BST 7 12 1, 7, 12, 25, 27, 13, 23, 17, 15 25 13 27 This situation is not uncommon e.g., the data is roughly sorted. 23 17 15 ITK 275

  6. Highly unbalanced BST 1 7 17 12 13 25 25 7 15 23 27 13 27 1 12 23 Balanced BST 17 15 ITK 275

  7. If R is too big, then Shift a Node from R to L 1. Insert to L is a BST 2. Find the min in R, 3. Copy to the root and delete it from R L R ITK 275

  8. How to measure the unbalance? How big is “too big”? How unbalanced do we allow a BST to be? Chung-Chih Li. An immediate approach to balancing nodes in binary search trees. Journal of Computing Sciences in Colleges , 21(3):238--245 April 2006. ITK 275

  9. Definition: NBkNode-Balanced of degree K ITK 275

  10. Insert a node to an NBk ITK 275

  11. Insert a node to an NBk ITK 275

  12. Delete a node from an NBk ITK 275

  13. Delete a node from an NBk ITK 275

  14. Analysis Average Heights on n Random Keys BST 1. 2. Devroye and Reed,, SIAM J. Comput. ‘95 ITK 275

  15. Analysis of NBk with nRandom Keys n the worst case a a2 X2 a3 X X3 ITK 275

  16. Analysis of NBk with nRandom Keys the worst case At depth h   ITK 275

  17. Analysis of NBk with nRandom Keys the worst case At depth h  BST: AVL: ITK 275

  18. Experimental results Computational Cost • AVL --- algorithm is complicated • NBk ---shiftingoperations • BST ---traveling long paths ITK 275

  19. Random and no duplication in data log(n) 1.2 M ITK 275

  20. 2.66 GHz P4 1GB M MS XP Visual C++ Random and no duplication in data ITK 275

  21. Random, each key has n/100 duplicates log(n) 1.2 M ITK 275

  22. 2.66 GHz P4 1GB M MS XP Visual C++ Random, each key has n/100 duplicates ITK 275

  23. Random, arrive in batches of 32 sorted records log(n) ITK 275 1.2 M

  24. 2.66 GHz P4 1GB M MS XP Visual C++ Random, arrive in batches of 32 sorted records ITK 275

  25. NBk Conclusion • can build a near optimal BST even when k is small • easy to analyze • easy to implement • practical in most conditions While NBk's computational cost is much better than BST and close to or better than AVL, there is no guarantee on any data. In other words, it is not as robust as AVL. ITK 275

  26. AVL Tree: A BST in which the height difference between the two children of any node is always less than 2. +1 +1 -1 h’ h’+1 h h+1 ITK 275

  27. Rotations: RR +1 +2 +1 ITK 275

  28. Rotations: RL +1 +2 0 h+1 +1 -1 0 0 h+1 +0 -1 h h ITK 275

  29. Rotations: LL +2 +1 +1 h+1 -2 -1 -1 0 h+1 -2 -1 0 h-1 h -1 0 h-1 h-1 ITK 275

  30. Possible complications Re-assign the links +2 h+1 -1 h+1 -1 h h Tracking the heights and balance-factors ITK 275

  31. AVL h: Average Heights n Random Keys ITK 275

More Related