[We hope that you can view the videos! However, if your internet connection is too slow for viewing videos, download the audio file (mp4) and the slides (pdf). Then you can listen to the audio as you go through the slides.]

Recursion

We introduce recursion from the beginning, repeating the materials given in the lecture just before classes got temporarily cancelled.

Slides for all 3 videos of this lecture: pdf

Part 1: Introduction and a matryoshka (Russian dolls) example

A recursive function is a function that calls itself. We discuss the nesting of Russian dolls and write a recursive function that simulates opening a set of Russian dolls.

Part 2: More examples

We discuss two more examples, doing a count down and computing the factorial of a number, to reinforce the pattern discussed previously: in a recursive function there is a part for the simple case (called the "base case") and a part for the complex case (recursive case).

Part 3: Divide and Conquer

Recursion is great for "divide and conquer"! There are 3 steps: (1) Decide how to deal with "small data" (the base case), (2) Decide how to break up the problem, (3) Decide how to combine the answers from the subproblems. The examples discussed are counting the number of 'e's in a string and removing blanks from a string.