Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Recursion

Session Overview
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

Lecture 6: Recursion (00:49:24)

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

Lecture code handout (PDF) Lecture code (PY)

Recitation Videos

Recitation 3: Lists and their Elements, Sorting, and Recursion (00:50:23)

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? 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? answer A recursive case calls the recursive procedure on a simpler case (usually a part of the input).

What is a base case? 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.

Instructions (PDF) Code Files (ZIP) (This ZIP file contains: 1 .txt file and 2 .py files.)

Solutions (ZIP) (This ZIP file contains: 3 .py files.)

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:

4.9 Recursion. How to Think Like a Computer Scientist. Recursion. An Introduction to Python. Comparing Recursion and Looping. An Introduction to Python.

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: o Dynamic programming I: memoization, Fibonacci, Crazy Eights, guessing

You might also like