• Very different from greedy algorithms
    • Greedy algorithms decide a rule and follow it blindly
    • Dynamic programming studies the problem more carefully
  • Solve the problem by building up solution from sub-problems
    • How to choose which sub-problems to consider ?
    • How to combine answers of sub-problems to solve the given problem ?
  • Dynamic programming might seem like we are actually doing brute-force search
    • But analysis will show we are doing much better

Fibonacci Numbers

Fibonacci Numbers: Memoization of recursion

To compute via , we need

  • one recursive call to
  • two recursive calls to
  • Instead of computing these Fibonacci numbers from scratch each time, can’t we just remember them to look up later as needed ?

Algorithm

Trimming the recursive tree to compute via memoization. Downward green arrows indicate writing into the memoization array & upward red arrows indicated reading from the memoization array.

Fibonacci Numbers (Intentionally filling up the array!)

Algorithm

Analysis of Running time

  • We store numbers in the array
  • Computing each new entry needs to look up two known numbers and perform one addition
  • Hence, total running time to compute is