Lecture 18
Learning objectives
After this class, you should be able to:
- Explain the following terms: tree, root, level, height, parent, child, ancestor, descendant, leaf, subtree, path, length of a path, binary tree, complete binary tree, and binary search tree.
- Derive bounds on the heights of different types of trees.
- Given a tree, show the order in which the vertices are visited with the following traversals: (i) preorder, (ii) postorder, (iii) inorder, and (iv) level-order.
- Given a tree, determine whether or not it is a binary search tree.
- Given a binary search tree, show the nodes visited while searching for an element.
- Derive the time complexity of searching a binary search tree.
- Write code to implement the four traversals mentioned above, and to search for an element in a binary search tree.
Reading assignment
- Section 6.4, except 6.4.3. However, you may find the material in section 6.4.3 interesting to read.
- Page 242.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Draw a binary search tree that stores the following data in a tree of minimum possible height: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 2.5, 3.5, 8.5.
- For the tree you drew above, give the value of the root node, and the parent and children of the node with key 10.
- Show the nodes visited while searching the above tree for key 13.
- Give the order in which nodes are visited when you traverse the above tree using level-order traversal.
- Give the order in which nodes are visited when you traverse the above tree using inorder traversal.
- Give the order in which nodes are visited when you traverse the above tree using preorder traversal.
- Give the order in which nodes are visited when you traverse the above tree using postorder traversal.
- Which type of traversal on a binary search tree will lead to the elements being visited in ascending order?
- Write code to perform a level-order traversal of a binary search tree.
- Let a ternary tree be one in which each node can have up to three children. Derive a formula for the number of nodes of a complete ternary tree of height
k
. What is the minimum height of a ternary tree with n
nodes? What is the maximum height of a ternary tree with n
nodes?
- Questions on next lecture's material
- Let a binary tree consist of only one node, with value
15
. If we wish to insert 3
and 18
, then what will the tree look like after the insertions?
Last modified: 26 Oct 2009