Start of Dynamic Programming | Recursion | Memoization


function
fib(n){
if (n <= 1) return n; return fib(n - 1) + fib(n - 2);}
                         fib(5)
/ \
fib(4) fib(3)
/ \ / \
fib(3) fib(2) fib(2) fib(1)
/ \ / \ / \
fib(2) fib(1) fib(1) fib(0) fib(1) fib(0)
/ \
fib(1) fib(0)
function fib(n) {  let lookup = new Array(MAX);  for (let i = 0; i < MAX; i++)
lookup[i] = NIL;
if (lookup[n] == NIL){ if (n <= 1) lookup[n] = n; else lookup[n] = fib(n-1) + fib(n-2); } return lookup[n];}

Keep learning, keep growing! —

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store