RECURSION EXERCISES
1. (Sedgewick, Exercise 5.3.) Give the sequence of argument values that result
when the following program is invoked for each of the integers 1 through 9.
int puzzle(int n) {
if (n == 1)
return 1;
if (n % 2 == 0)
return puzzle(n/2);
else
return puzzle(3*n+1);
}
2. (Sedgewick, Exercise 5.6). Give the nested sequence of function calls for
Euclid's gcd algorithm with inputs 89 and 55, as in Sedgewick Figure 5.2.
3. Sedgewick, Exercise 5.29.
4. Sedgewick, Exercise 5.30.
5. Sedgewick, Exercise 5.33.
6. Sedgewick, Exercise 5.39. Assume expressions are evaluated from
left to right. (In C, the order of evaluation is not specified.)
There are many more exercises on recursion in "Notes on Recursion."