CS 215 ­ Fundamentals of Programming II  Spring 2011 ­ Homework 13 20 points Out: April 8

advertisement
CS 215 ­ Fundamentals of Programming II Spring 2011 ­ Homework 13
20 points
Out: April 8
Due: April 13 (Wednesday)
1. (8 points) For each sequence of characters, draw the binary search tree (BST) that results after inserting the sequence of characters into an empty BST. Then give the order the nodes are visited when the tree is traversed by in­order, pre­order, and post­order scans.
a) F, L, O, R, I, D, A
b) R, O, T, A, R, Y, C, L, U, B
2. (4 points) Consider the following BST:
50
25
80
20
35
30
27
70
45
33
95
75
47
90
98
93
Re­draw the tree after erasing values 27, 45, and 80.
3. (4 points) Use the integers from 0 to 9 to build a ten­node BST. Draw one example BST for each possible root node value for a tree of depth 4. That is, draw a BST where 0 is the root value, where 1 is the root value, etc. (Recall the definition of the depth of a tree is the maximum depth of any node in the tree.)
4. (4 points) Write a template function bst_minimum that receives the root (BTNode) pointer of a BST and returns the minimum value in the tree. Note: you are not required to implement this function in a program that runs, but you can if you want to.
Revised after class 04/08/2011
Page 1 of 1
D. Hwang
Download