CompSci 100e Spring11
Classwork 13: How Many BSTs?
Name & NetID: ___________________________________
Name & NetID: ___________________________________
Name & NetID: ___________________________________
-
In a complete binary tree, every non-leaf node has two
children, and all the leaves are at the same level. Two examples of
complete trees are shown below.
If there are n levels in a complete tree (the tree on the left
above has two levels, the tree on the right has four) what is the total
number of nodes in the complete tree (both leaves and internal
nodes) and the total number of leaves in the complete tree.
Express answers in terms of n.
-
The pre-order traversal of a binary tree (not a search tree)
is as follows:
x p q r s a d k z o
The in-order traversal of the same tree is the following,
draw the unique binary tree with these pre- and in-order traversals.
q p r s x d k z a o
-
There is one binary tree with one node. There
are two differently shaped trees with two nodes.
There are 14 different (shaped) binary trees
with four nodes. These different trees are shown below.
- Draw all five of the different binary trees with three nodes.
- Using the information about how many trees there are with
1, 2, 3, and 4 nodes determine how many different binary trees
there are with 5 nodes. Do not draw them, but reason
about how many there must be based on:
- There is a root node.
- There are four other nodes that are distributed between
the left and right subtrees.
For example, there must be 28 different five-node trees in which all the
nodes but the root are either in the left subtree or all in the right
subtree (why?)
- Can you make a different number of legal BSTs with different elements? That
is, can you make a different number of trees with the elements
(1,1,1) vs. (1,2,3) vs. (-4,72,0)? Why or why not?
- Complete the BST count
APT. Will you solution return an answer in under 3 seconds for trees with 25 elements?