CS140: Homework 11
Do not be intimidated by the number of problems in this homework. Most of them
require a very short answer.
- Weiss 4.8
- Weiss 4.9
- Show the result of deleting C from the tree in Figure 4.59 in Weiss.
- What is the height of the tree in Figure 4.59 in Weiss?
- What is the depth of the following nodes in Figure 4.59 in Weiss?
- 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;
- In the previous problem does your function do a pre-order or post-order
traversal of the tree? Why?
- What is the problem with the following function? How would you fix it?
int fact(n) {
return n * fact(n-1);
}
- Rewrite the FindMin function in Figure 4.19 of Weiss so that it uses
iteration rather than recursion.