Date:: January 23rd, 2025
Synopsis
We will talk about recursion, the second most powerful idea of
computer science. We assume you have seen recursion before, as well as
proofs by induction. This ties the two concepts together and shows you
how to write recursive functions in
Before watching the videos, think about these questions for five minutes or so.
-
Did you know that if you take the first odd numbers and sum them, that the result is ? i.e.,
Try to prove this by induction; remember you need a base case (when \(n=1\)) and an induction case (when l).
-
In your favorite language, try to write a recursive function that computes in the same way, by summing the first odd numbers.
-
Imagine that you had a recursive function that never made use of the result of its recursive call. Would such a function even be useful? (Hint: the answer is “yes”.) What kinds of things could you do if you could guarantee to the compiler that this would be the case?
Videos
Activities
Further Reading
- There and Back Again This is a research paper about a hybrid of forward recursion and tail recursion.