CS140 -- Final Exam: December 7, 2004


Question 5: 10 points

Behold the following B-Tree, where M = 4:

Part 1

Specify the values that are held in the three interior nodes. Specify them as "Root", "Left-Child", and "Right-Child".

Part 2

Draw the tree that results when 15 is inserted into the tree. Include in your drawing the values in both the interior and exterior nodes.

Question 6 -- 15 points

Behold a typedef for a binary tree node:

typedef struct btreenode {
  Jval key;
  struct btreenode *left;
  struct btreenode *right;
} BTreeNode;

Your job is to write a procedure:

   int is_bstree(BTreeNode *root, double *min, double *max); 

Is_bstree() assumes that it is passed the root of a binary tree, and that the keys are doubles. It returns 1 if the tree is a valid binary search tree, and 0 otherwise. The binary search tree should not have duplicate keys. It also returns the minimum and maximum keys in the tree through the arguments min and max.