Analysis of algorithms · Study questions
Fall, 2010 · Department of Computer Science · Grinnell College

For Wednesday, September 29

Consider the Fibonacci sequence defined by recurrence equations (3.22) on page 59 of our textbook.

  1. Write, in Scheme, a straightforward recursive procedure fibthat takes any natural number as argument and returns the number in the specified (zero-based) position in the Fibonacci sequence. Test your code. Express the number of recursive calls required to compute (fib n) as a function of n.
  2. Write a memoized recursive version of the fib procedure, using a vector to hold previously computed results. Again, express the number of recursive calls required to compute (fib n) as a function of n.
  3. Write an iterative (i.e., tail-recursive) version of the fib procedure, still using a vector to hold previously computed results, but filling up the vector in a plausible order.
  4. All of the preceding solutions use Θ(n) memory locations to compute (fib n). Write an iterative version of fib that works in Θ(1) space.

· ·
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.

This text is available on the World Wide Web as

http://www.cs.grinnell.edu/~stone/courses/algorithms/study-questions.html


John David Stone · stone@cs.grinnell.edu