Lecture 21
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.
- Write code implementing self-restructuring BSTs, using single rotations and move-to-root.
- Given a sequence of insert and search operations on a BST, draw the resulting tree when one of the self-restructuring techniques mentioned above is used.
- Given an application, suggest a suitable self-restructuring technique for it (which may be different from those discussed in class).
- Given a BST and probabilities of searching for nodes in it, derive the average search time.
Reading assignment
- Section 6.7.2 (deletion) and section 6.8, up to (and including) 6.8.1.
- Pages 271-272.
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.
- Insert the following data into a self-restructuring BST:
8, 4, 10, 2, 6, 9
. Show that tree that results from searching for 6
using each of the following techniques: (i) single rotation, and (ii) move to the root.
- Assume that the probabilities of searching for the nodes of a complete BST of height
h
are all equal. Give the average time to search for a node as a function of the number of nodes in the BST.
- Questions on next lecture's material
- Draw the array corresponding to figure 6.51 (c).
Last modified: 1 Nov 2004