Lecture 15
Learning objectives
After this class, you should be able to:
- Given a binary search tree (BST) and an element to be inserted, draw a figure to show the BST after that element has been inserted.
- Given a BST and an element to be deleted, draw a figure to show the BST after that element has been deleted.
- Give the time complexity for insertion and deletion in a BST.
- Write code for insertion and deletion in a BST.
Reading assignment
- Sections 4.3, pages 129-133.
- Lecture: Trees: Part 3 -- Binary search trees.
- None.
Exercises and review questions
- Exercises and review questions on current lecture's material
- In the BST of review question 1 of the previous lecture, delete (i) a leaf and (ii) a node with two children. Draw a figure to show the BST after these deletions.
- When deleting a node with two children, we copied the value of the smallest node in the right subtree. If the data stored there is very large, then this operation is inefficient. Write code that changes pointers to move the smallest node in the right subtree to the location of the node to be deleted, in order to avoid this copying.
- Questions on next lecture's material
- None.
Last modified: 1 Oct 2011