Functional Problem Solving (CSC 151 2014F) : Outlines

Outline 29: Numeric Recursion


Held: Friday, 17 October 2014

Back to Outline 28 - Other Forms of List Recursion. On to Outline 30 - Preconditions, Revisited.

Summary

We visit a slightly different kind of recursion, numeric recursion. In this technique, we once again have procedures call themselves. However, the parameter that we "simplify" at every step is a number, rather than a list.

Related Pages

Overview

Administrivia

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Patterns of Recursion

While we've seen and written a variety of examples of direct recursion, they typically have the following form:

(define RECURSIVE-PROC
  (lambda (PARAMS)
    (if (BASE-CASE-TEST)
        (BASE-CASE PARAMS)
        (COMBINE (PART-OF PARAMS)
                 (RECURSIVE-PROC (SIMPLIFY PARAMS))))))

For lists, the simplification was almost always "take the cdr" and the "part-of" was almost always "take the car".

Recursion with Numbers

Lab