# Outline for May 27, 2009

1. Recursion
1. Express problem in terms of itself
2. Recursive definitions
1. Base case (not recursive)
2. Recursive part (must eventually reduce to base case)
3. Relationship to mathematical induction
2. Example: n! (see fact.py)
1. Definition
1. Base case: 0! = 1
2. Recursive part: n! = n(n−1)!
2. Show stack for n = 3
3. Example: reverse string (see reverse.py)
1. Definition
1. Base case: empty string
2. Recursive part: reverse(s) = reverse(s[1:]) + s
2. Show stack for s = “yes”
4. Example: binary search (see binsearch.py)
1. Definition
1. Base case: high < low, return failure; word is list[mid], return mid
2. Recursive part: if word < list[mid], search word[0..mid-1]; if word > list[mid], search word[mid+1..high]
2. Show for list.txt from last time
5. Example: list of permutations of string (see perm.py)
1. Definition
1. Base case: empty string gives list of empty string
2. Recursive part: for each permutation of (string without first char), put first letter of this string in each position
2. Show stack for s = “012”
6. Example: Fibonacci numbers (see rfib.py)
1. Definition
1. Base case: fib(0) = 1, fib(1) = 1
2. Recursive part: fib(n) = fib(n−1) + fib(n−2)
2. Show stack for n = 3