[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.]
We continue our discussion on recursion. Here are the slides for all 3 videos of this lecture: pdf. The answers to the questions asked during this lecture are in a separate file at the end of this page.
We focus on what happens in memory when we execute a recursive function: the call stack grows with each recursive call, until a base case is reached and the call returns. All the calls eventually wrap up, accumulating the final result.
There are different ways to break up the problem into parts, but you need to make sure that each part will progress to the base case eventually and that the answers from the parts are combined correctly.
Given a "family tree" represented using a Person
objects, we write a function to determine the number of ancestors that a person has.
Person
then.Answers to the first 4 questions asked during lecture: pdf