Hi there!

You need to be logged in to view this course.

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;

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