# Class 17: Recursion with Natural Numbers

Reading: Recursion with Natural Numbers. Lab: Recursion with Natural Numbers. Back to More Recursion with Lists. On to Pairs.

Held Monday, February 19, 2001

Summary

Today we consider recursion over a different domain, the natural numbers.

Assignments

Handouts

Notes

Overview

• Reflections on recursion
• Introduction to numeric recursion
• Lab

## Reflections on List Recursion

### Patterns

• Let's try to identify some patterns of recursion over lists.
• That is, the general structure of kinds of Scheme procedures that work on lists.
• Here's one category of recursion that we did a few times: apply some operation to every element of a list.
• How do we express the general form of that category?
• What other kinds of things do you do to lists?
• What is the general form for those things?

### Problems

• What things are likely to be difficult or wrong in one of your recursive procedures?
• I see many people having trouble with the base case. It may help to think about what kind of thing the procedure should return.
• I know that you sometimes write procedures that run forever (I do, too; I wrote one yesterday). Make sure that when you do the recursive call, you're using something closer to the base case.

## Recursion with Numbers

• While most of the recursion we've been doing has used lists as the structure to recurse over, you can recurse with many different kinds of values.
• It is fairly common to recurse using numbers.
• The natural base cases for integers are when you hit 0 or when you hit 1.
• The natural parameter for recursive procedure calls typically involves subtracting 1 from the argument.

## History

Friday, 12 January 2001

• Created generic outline format for class.

Sunday, 18 February 2001

• Filled in the details.

Back to More Recursion with Lists. On to Pairs.

Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Wed May 5 12:14:55 2004.
This page may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/outline.17.html`.