Class 31: Numeric Recursion
Held:
Preliminaries
Related Pages
-
Reading: Numeric Recursion
-
Lab: Numeric Recursion
Updates
News / Etc.
- New partners!
Rotating reminders
- Visit review sessions! I run review sessions on Thursdays at 9am in this room.
- Visit mentor sessions! We have mentor sessions on Thursday evening from 8:00-9:00 p.m. in the CS Commons.
Upcoming Work
- Lab writeup: Execise 3
- Reading for Friday: Naming Local Procedures
- No homework over break.
- Friday’s quiz: Identify your classmates
Extra credit (Academic/Artistic)
Extra credit (Peer)
- Singers Concerts during spring break.
- If there is an admission fee, I will reimburse up to $20.
- Baseball games during spring break (Arkansas & Alabama).
- If there is an admission fee, I will reimburse up to $20.
- Baseball games last weekend of spring break. (1 hour suffices; no more than two units for the weekend.)
Extra credit (Misc)
Good things to do
- Ultimate games during spring break.
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
- 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 simplification step for recursive procedure using numbers calls typically involves subtracting 1 from the argument.
- Other simplifications, such as dividing in half, are also possible.
Lab
- Do the lab