180 likes | 330 Vues
This document provides an insightful introduction to AVL trees, focusing on their definition as balanced binary search trees that maintain a height difference of at most one between left and right subtrees. It covers the history of AVL trees, the mechanics of single and double rotations, and discusses their time complexity. Additionally, it includes practical exercises on inserting numbers to reinforce learning. By maintaining a balance condition, AVL trees ensure efficient search, insertion, and deletion operations, all of which are critical for optimized data structure performance.
E N D
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. • 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.
Single Rotation • The book covers this point very clearly. page 120
Single rotation cont.. Perform Single Rotation
Double Rotation • Figure 4.34 in the book page123
Double Rotation cont… Double Rotation
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
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 .
Practice • Input these numbers in an AVL tree. • 3,2,1,4,5,6,7,16,15,14 • Here is how you start,
Practice cont… • Here is the final tree!!!