๐๐ผ

# Dynamic Programming and Fibonnaci

No, this video is not about Ruby, Python, JavaScript, etc. Dynamic programming is a way to solve a problem using an algorithm in a fairly prescribed way. It sounds complicated, but itโs anything but.

Dynamic programming gives us a way to elegantly create algorithms for various problems and can greatly improve the way you solve problems in your daily work. It can also help you ace an interview.

You knew Fibonacci was going to come up in this book at some point didnโt you! Well, here it is. Iโm using it here because itโs the simplest way to convey the dynamic programming process. Also: you will be asked how to solve Fibonacci at some point in your career, and youโre about to get three different approaches!

Which leads right to a great opening point: our jobs are about solving problems. When you go to these interviews, they mostly want to see how you would go about solving something complex. As it turns out, the Interviewing For Dummies book says that Fibonacci is a great question for just that case.

## The Code

``````//Fibonacci with Dynamic Programming
const calculateFibAt = (n) =>{
var memoTable = [0,1];
for(var i=2;i<=n;i++){
memoTable.push(memoTable[i-2] + memoTable[i-1])
}
return memoTable;
};
console.log(calculateFibAt(1000));

//slow, recursive way
const fibSlow = n => n < 2 ? n : fibSlow(n-2) + fibSlow(n-1);

console.log(fibSlow(10));
``````