Name: ________________________________
Honor Code Acknowledgment: ___________________
Due: February 7
True or False: In every non-empty binary tree there exists a node with no parent. (justify your answer)
The height of a one-node tree is 0, the height of a non-empty tree is the number of edges on the longest root-to-leaf path (on a path, the number of edges is always one less than the number of nodes.)
Ed Jones
What is the minimum height of a binary tree that contains 31 nodes? What is the maximum height of a binary tree that contains 31 nodes?
Ed Gaedel
What is the minimum height of a binary tree that contains 1,023 nodes? What is the maximum height of a binary tree that contains 1,023 nodes?
Bo Diddley Squat
Consider a tree in which each node contains a maximum of 4 children (a quad tree). What is the minimum height of a quad tree that contains 21 nodes, what is the maximum height of a quad tree that contains 21 nodes?
Bicep,Tricep
What is the minimum height of a quad tree that contains 21,845 nodes?
The function below is intended to return false if its parameter is NOT a binary search tree and true if it is a search tree. It does not work as intended. Draw a tree that is not a search tree, but for which the function returns true.
bool IsBST(Tree * t)
{
if (t == 0)
{
return true; // empty tree is a search tree
}
else if (IsBST(t->left) && IsBST(t->right))
{
return true;
}
else
{
return false;
}
}
What is the output of the following function:
struct Tree
{
string info;
Tree * left;
Tree * right;
};
void Print(Tree * t, ostream & out)
{
if (t != 0)
{
out << t->info << endl;
Print (t->left, out);
Print (t->right, out);
return false;
}
}
If t points to the following tree on the first call to Print: