Recursion
Solves a problem by breaking it down into smaller instances of the same problem. If you can solve a smaller instance of the problem, you can solve a larger one.
- Base Case(s): The simplest instance(s) of the problem that can be solved directly without further recursion.
- Recursive Case(s): More complex instances of the problem that are solved by breaking them down and making recursive calls.
Goal: Move disks from peg using peg .
Rules: Only one disk can be moved at a time, and a disk can only be placed on top of a larger disk.
We define the problem as :
- Move top disks via :
- Move 1 disk
- Move top disks via :
Recurrence relation
We "solve" a recurrence relation by finding a closed-form expression for in terms of .
- Expand the relation as to 3 levels
- Observe the pattern of
- Generalize the pattern in terms of the level
- Using the base case to define in terms of
- Subsitute back into the generalization
- Geometric series:
- Arithmetic series:
- Factorial:
- Falling factorial:
- Logarithm:
- Logarithm property:
The master theorem can give us the order of growth (Big Theta) of a recurrence relation.
For , we have:
Mathematical induction
A method of mathematical proof that proves a statement for all natural numbers.
- Base case: Prove the statement for the first natural number in the statement's range.
- Inductive step: Assume the statement is true for , then prove it is also true for .