Computer Science Fundamentals/ Data Structures and AlgorithmsLESSON 21 OF 34Log inSubscribe
Dynamic Programming and Fibonnaci lesson slide
LESSON 21 OF 34 · IN THE FULL COURSE

This one's part of the full course

Good to see you. This one's in the full course

8 lessons are free to watch right now, no account needed. If they click, grab the course and every lesson is yours to keep.

You've seen how I teach. The other 26 lessons are in the full course, and your progress comes with you.

Already bought it? Log in and it picks up right here.

Your progress comes with you the moment you buy.

Data Structures and Algorithms · LESSON 21

Dynamic Programming and Fibonnaci

Discuss
THE COURSE, END TO ENDNow playingDoneAheadYou are hereFree to watchIn the full course
Foundations
Logic and Binary
Information Theory
Crypto
CS Theory
Data Structures and Algorithms
Software Design
Core Skills
ABOUT THIS LESSON

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));
34lessons across 8 sections
8free to watch right now
Foreverbuy it once, it's yours for life

34 lessons · 9.6 hours · all done

You finished Computer Science Fundamentals.

Every lesson, start to finish. That takes some doing, and you did it. Now go build something with it.

Cheers! Rob