Memoization to Speed Up Recursion; The Master Theorem

Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=Ly65M0ZbddQ



Duration: 1:04:26
123 views
2


We did about two hours of lab time today to let students write a recursive program to compute the super Fibonacci sequence (where you add three numbers together instead of two) using bigints. The recursive algorithm is easy to write, but suffers from an exponential running time. Oof. But since it is going to be computing the same values over and over, we can create a little cache to write down the answer any time we compute a value, and if we are ever asked to compute that value again, we can just use the cached value instead. This speeds it up from exponential running time to linear - nice!


We then talked about the Master Theorem (sometimes called the Master Method) which will tell you the Big O running time of a certain class of recursive algorithms. You have to compute three values:
A: How many times the function calls itself
B: What fraction of work (B is the *denominator*) goes to each of the sub-calls
C: How much work is done at each level in terms of O(N^C). C is the exponent! So for constant running time, C is 0, for linear, C is 1, for N^2, C is 2, etc.


You then compare log(base B)(A) and C, and use the formula to get the Big O running time of the algorithm







Tags:
csci 26
Memoization
Caching
Master Method
master theorem