













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














Now that we have seen how to balance a tree, we are ready to look at the algorithms. The search and retrieval algorithms are the same as for any binary tree. However, because the AVL tree is a special case of a binary search tree, you will want to use an inorder traversal method. Docsity.com
As with the BST, all inserts take place at a leaf (or leaf-like) node. To find the appropriate leaf node, we follow the path from the root, going left when the new data node’s key is less than the root node’s key and right when it’s greater. Once we have found the leaf, we connect the new node to the leaf and begin to back out of the tree.
The delete logic is similar to the BST delete logic. Again, however, we must make sure that we include the logic to keep the tree balanced.
Height 0 1 2 3 4 5 6 7 8 9 10 Num Nodes 1 2 4 7 12 20 33 54 88 143 232
Let N be the fewest number of nodes in an AVL tree of height H It is straightforward to show that N = F(H+3) - 1 , where F(k) is the k th^ Fibonacci number For large values of k ,
1 5
1 + 5 2
k
Solving for H
get
This means that the height of an AVL
larger than the optimal height of a