Lecture 18
Learning objectives
After this class, you should be able to:
- Write code to implement deletion from an AVL tree, and give its time complexity.
- Given a sequence of insertions into an AVL tree, and deletions from it, draw the tree.
- Explain the correctness of the algorithms for insertion and deletion in an AVL tree.
Reading assignment
- Section 4.4.
- Lecture: Trees: Part 4 -- AVL trees.
- None.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Insert the following elements into an AVL search tree in the order given below:
8, 4, 10, 2, 6, 9, 11, 12, 1, 3, 5, 7, 0, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1
. Show the AVL tree that results from deleting the node with key value 9.
- Insert the following elements into an AVL search tree in the order given below:
8, 4, 10, 2, 6, 9, 12, 11, 1, 3, 5, 7, 0, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1
(note that 11 and 12 are inserted in a different order than in the previous question). Show the AVL tree that results from deleting the node with key value 9.
- Complete the figures for case 2 in insertion and deletion by giving the heights of all the vertices.
- Let the balance factor of a node be defined by | Height of right sub tree - Height of left sub tree |. Give the balance factor for the nodes in slides 27-30. Instead of storing the heights of the nodes, can we store the balance factors of the nodes and update an AVL tree (for insertion and deletion) based on this information?
- Questions on next lecture's material
- None.
Last modified: 13 Oct 2011