CS 1 Fall 2007

Big Idea

Recursion

Monday, October 8, 2007


From the dictionary:

Recursion -- n. See recursion

Recursion is a powerful tool which allows us to solve many large problems---both problems which are unbounded in size and problems which are conceptually difficult as a whole. In many case, we only need to figure out how to do two simple things:

We code our programs to simply "know" the answers to one (or at most a few) trivial instances (the base cases), and to build larger solutions from smaller ones. Our recursive solutions are very closely related to inductive proofs in mathematics. In fact, part of their power is that we can easily verify their correctness, and when necessary, prove their correctness inductively.

If we simply write a Scheme expression, we will always have a finite number of operators in any expression. However, many times we need an unbounded number of operators---that is, a number of operators that depends on the size of the arguments to the procedure. E.g. If we want to calculate N! (N factorial), we will need (N-1) multiplications. Recursion allows us to do this. We simply know that:

The expressions we write to perform all these multiplications need only have a single multiplication (the one in the reduction step), but, through recursive procedure invocation, that one multiplication serves to provide us with the (N-1) multiplications we need to solve the problem.

All large problems are solved by reducing them to simpler problems and combining the results.