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. |
About this Video
Topics covered: Dictionaries, modular abstraction, divide and conquer, recursion, tower of Hanoi, base case, Fibonacci sequence.
Resources
Recitation 3: Lists and their Elements, Sorting, and Recursion
> Download from iTunes U (MP4 - 109MB)
> Download from Internet Archive (MP4 - 109MB)
About this Video
Topics covered: Tuples, lists, iteration, list elements, sorting lists, mutability, keys, dictionaries, chain method, recursion, base case, Tower of Hanoi.
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.
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 is assigned in this session. The instructions and solutions can be found on the session page where it is due, Lecture 7 Debugging.
These optional resources are provided for students that wish to explore this topic more fully.
After watching the lecture, you may want to read some of the following resources: