Homework 3
CS409 - Spring 2000
Due: Thursday, Feb 17
- (10 pts) Suppose we wish to insert the keys A L G O R I T H M F U
N into a Dictionary. The keys are presented for insertion in the order
given and are stored in alphabetical order within the Dictionary.
- Show the resulting Binary Search Tree (BST).
- Show the resulting 234-Tree.
- (15 pts)
- Show all the legal BSTs that can be made using the elements A, B, and
C. Note that for a tree to be legal it must satisfy the BST
Property (i.e., the elements must remain in correct alphabetical order
within the tree).
- How many different, legal BSTs can be made using the elements A, B, C,
D, and E? Show your work. Hint: You should be able to
answer this question without listing all the trees. Start by
determining the number 4-node trees through use of your knowledge of the
number of 1-, 2-, and 3-node trees.
- Show all the legal 234-Trees that can be made using the elements A, B,
C, D, and E.
- (5 pts) For a BST, is delete commutative? In other words, if
we delete x then y, do we always get the same answer as when
we delete y then x? Either argue that delete is
commutative or give a counterexample.
- (10 pts) Suppose we design a BST that contains some extra
information at each node: each node will contain a field showing the number
of items held within the corresponding subtree.
- Briefly explain how this information can be kept up-to-date when a new
item is inserted.
- Briefly explain how this information can be used to do selection.
[Select(k) is meant to return the k-th smallest item that
is currently in the Dictionary. For example, Select(1) should
return the smallest item and Select(n/2), where n is the
number of items in the Dictionary, should return the median item.]