# Class 08: Recursion with Numbers

Back to Recursion with Lists. On to Local Bindings.

Held: Friday, 31 January 2003

Summary: Today we consider recursion over a different domain, that of the natural numbers.

Related Pages:

Assignments:

Notes:

• Are there questions on Homework 1?
• The consensus in all three of my classes is that others can visit as long as they are quiet and don't take computers needed by students in the class. So, you can feel free to work in the MathLAN from 2:15-4:05 (and beyond).
• Did anyone write the efficient exponentiation procedure iteratively?
• Yes, it's possible to write every recursive procedure iteratively. It's just not always easy, and the resultant code isn't always readable. It is also possible to write every iterative procedure recursively.

Overview:

• Introduction to numeric recursion.
• Lab.

## 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 the parameter reaches 0 or 1.
• There are, of course, other alternatives
• The natural parameter for recursive procedure calls typically involves subtracting 1 from the argument.
• There are, of course, other alternatives.

## Lab

• Do the lab.
• Since it's comparatively short, we should have a few minutes to reflect at the end.

## History

Thursday, 15 January 2003 [Samuel A. Rebelsky]

• Created as a mostly-blank outline.

Back to Recursion with Lists. On to Local Bindings.

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

This document was generated by Siteweaver on Tue May 6 09:20:22 2003.
The source to the document was last modified on Thu Jan 16 15:16:11 2003.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Outlines/outline.08.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu