1 / 18

Chirag Patel

Chirag Patel. AVL trees. 18/4/2003 Enjoy. AVL Trees Introduction. 4.4 AVL trees History Single Rotation Double Rotation Time Complexity Usage. History. An AVL (Adelson – Velskii and Landis) tree is a binary search tree with a balance condition.

Download Presentation

Chirag Patel

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. Chirag Patel AVL trees. 18/4/2003 Enjoy.

  2. AVL Trees Introduction • 4.4 AVL trees • History • Single Rotation • Double Rotation • Time Complexity • Usage

  3. History • An AVL (Adelson – Velskii and Landis) tree is a binary search tree with a balance condition. • A balance condition must be maintained and this ensures that the depth of the tree is O(log N). • ALV tree is a binary tree however we take into consideration that ever node in the tree the height of the left and the right sub tree can differ by at most 1.

  4. AVL Tree Example

  5. Single Rotation • The book covers this point very clearly. page 120

  6. Single rotation cont.. Perform Single Rotation

  7. Single Rotation cont..

  8. Example of Single Rotation

  9. Double Rotation • Figure 4.34 in the book page123

  10. Double Rotation cont…

  11. Double Rotation cont… Double Rotation

  12. Double Rotation cont…

  13. Example of Double Rotation

  14. Time Complexity • I would recommend that you go to this site to better understand the time complexity, as well as a few more ideas on AVL trees. • http://www.ecf.utoronto.ca/apsc/courses/ece242/2004spring/notes/bst2.pdf

  15. Before the quiz • Insert these numbers into a AVL tree. • Remember AVL tree is a binary search tree but a tree that is balanced. • Important this is the same when you insert a node or when you delete a node. • Hence the difference of left sub tree and the right sub tree should be no more than h = 1. • Practice these inputs because we might have a quiz today .

  16. Practice • Input these numbers in an AVL tree. • 3,2,1,4,5,6,7,16,15,14 • Here is how you start,

  17. Practice cont… • Here is the final tree!!!

  18. THE END

More Related