Recursion

OCW Scholar

« Previous | Next »

Session Overview

Photograph of a rabbit.

This lecture finishes the discussion of dictionaries, then introduces inductive reasoning and recursion. Examples include generating the Fibonacci sequence and solving the Towers of Hanoi problem.

Image courtesy of Stephen & Claire Farnsworth on Flickr.

Session Activities

Lecture Videos

About this Video

Topics covered: Dictionaries, modular abstraction, divide and conquer, recursion, tower of Hanoi, base case, Fibonacci sequence.

Resources

Recitation Videos

About this Video

Topics covered: Tuples, lists, iteration, list elements, sorting lists, mutability, keys, dictionaries, chain method, recursion, base case, Tower of Hanoi.

Check Yourself

What is recursion?

View/hide answer

Recursion, or "divide-and-conquer", allows us to define a function that calls itself to solve a problem by breaking it into simpler cases.

 

 

What is a recursive case?

View/hide answer

A recursive case calls the recursive procedure on a simpler case (usually a part of the input).

 

 

What is a base case?

View/hide answer

A base case is necessary in recursion; it determines when the procedure returns a value (or terminates), rather than continuing the recursive process.

 

 

Problem Sets

Problem Set 2: Successive Approximation and a Wordgame (Due)

Successive approximation is a problem-solving method where you try to guess the right answer to a problem and then check your guess. If the guess is good enough, you're done. Otherwise, you keep improving your guess in small increments and checking it, getting closer and closer to the right answer, until you determine that the guess is good enough. For the first 3 problems of this problem set, we will look at Newton's method, which uses successive approximation to find the roots of a function.

Secondly, we will have some fun with Python, and get some practice using strings and string operations. We would like you to implement the word game Hangman as a 1-player game against the computer.

Problem Set 3 (Assigned)

Problem set 3 is assigned in this session. The instructions and solutions can be found on the session page where it is due, Lecture 7 Debugging.

Further Study

These optional resources are provided for students that wish to explore this topic more fully.

Readings

After watching the lecture, you may want to read some of the following resources:

Related Lectures

  • 6.006 Introduction to Algorithms. 6.006 lectures assume a greater level of mathematical sophistication than does 6.00SC. Read the lecture notes on:
    • Dynamic programming I: memoization, Fibonacci, Crazy Eights, guessing

 

« Previous | Next »