CS140: Homework 11

Do not be intimidated by the number of problems in this homework. Most of them require a very short answer.

  1. Weiss 4.8
  2. Weiss 4.9
  3. Show the result of deleting C from the tree in Figure 4.59 in Weiss.
  4. What is the height of the tree in Figure 4.59 in Weiss?
  5. What is the depth of the following nodes in Figure 4.59 in Weiss?
  6. Write a recursive function to compute the height of a tree given a pointer to a node as a parameter. You can use the following definition for a node:
         typedef struct tnode {
             int value;
    	 struct tnode *left_child;
    	 struct tnode *right_child;
         } node;
         
  7. In the previous problem does your function do a pre-order or post-order traversal of the tree? Why?
  8. What is the problem with the following function? How would you fix it?
         int fact(n) {
             return n * fact(n-1);
         }
         
  9. Rewrite the FindMin function in Figure 4.19 of Weiss so that it uses iteration rather than recursion.