Fibonacci Sequence Recursion Explained (JavaScript)

preview_player
Показать описание
We walkthrough an example problem: "Find the nth number in the Fibonacci Sequence" to better understand how to code recursive solutions to problems.

5:45 - Recursive explanation begins (video starts with a non-recursive iterative solution)

First, we solve the problem with a non-recursive JavaScript solution which uses shifting "pointer" variables to calculate the numbers of the sequence.

Next, we look at a recursive solution and see how functions are pushed to the call stack to solve specific branches of a recursive tree. We begin to understand the amount of calculation behind a recursive solution and start to see areas for improvement. That is we begin to see places where we could improve performance by memoization, or remembering the values of past calculations.
Рекомендации по теме
Комментарии
Автор

thankyou for explaining this code in such a simple and beautiful way I really loved it your channel is worth subscribing

amitbhosale
Автор

Now I see why memoization is helpful. @11:06 where you said were not remembering the value of fib(3). I didn't realize that this function had to call fib(3) again. Thank you for walking through this. I know this is about explaining mainly recursion, but I've been going through different videos trying to understand how the memoization works and you just made it click.

bubbyprime
Автор

10/10 explanation. Been struggling to put these pieces together myself for hours and your video made it crystal clear. Thanks so much!!!

matthewc.
Автор

This was THE video that helped me understand this and taught me high to climb through it. The only thing I see here that is an issue is that the fib sequence actually starts at 0, so you'll want your "prev" variable to be 0, not 1, to be truly accurate. But if you just want to understand the logic in as plain English as possible, this is IT!

internetdrew
Автор

this was such a good explanation !! when I was calculating my fib function using math I was not understanding how the correct number in the sequence was getting outputted but I forgot about calculating the base case ! it was very helpful going through line by line and each call stack. I admit I had to watch 5 times before I really got it but a great video and great explanation!

dolicious
Автор

this video has finished my all thank you dear

shahriarahmedraktim
Автор

hey you... you´re my hero, this is the best explanation of the fibonacci sequence I´ve ever seen. Very beautifully detailed and clear. thanks!

criaturaimaginaria
Автор

Amazing walkthrough of what's going on in the call stack! That really clarified things for me!

joyannejoy
Автор

Thank you so much for such a detailed explanation!

nauilnil
Автор

Really insightful explanation. concise and straight to the point. Thank you!!!

KwabenaAgyemanLipsy
Автор

This is the best explanation i've ever seen. Protect this man at all cost!

albatalu-ali
Автор

Thank you for the great explanation! Very clear and easy to comprehend.

bobthehuntsman
Автор

Video was awesome, was having a hard time understanding the process between the input and output of a recursive function, this cleared it up, thank you for the help! Also what color theme are you using here?

robbiemclaughlin
Автор

A very elaborated explanation.Thank you!

mahfujhossain
Автор

This is a great video, thank you for making it !

TheToxicPepsi
Автор

Hey I am a bit confused, you said we do not remember the value of fib(3) when trying to calculate fib(5) since it was popped off the stack, which made 100% sense @11:06; however, earlier when calculating fib(4) you said "we just returned the value of fib(3) so we know it" but how is this possible if it was popped off the stack?? @9:20 is it because it was the previous calculation of fib(4)? sorry for the weird question, loved the video tho man, great stuff!

froylanrodriguez
Автор

function fib(n) {
let fibList = [];
if (n < 2) {
fibList.push(0);
} else {
let prev = 0;
let curr = 1;
fibList.push(prev, curr);
for (let i = 2; i < n; i++) {
const next = prev + curr;
prev = curr;
curr = next;
fibList.push(curr);
}
}
console.log(fibList);
}

AddictedToCode
Автор

Fantastic video! Thank you! Clearly demonstrates a confusing topic. Do you have a video showing how you got the dubugger to run correctly in VSC?

kirs
Автор

Thanks a lot for your great explanation! How did you configured your launch.json to automatically show the call stack and variables values? I can't find a way to do it. Thanks!

tidumarco
Автор

why is i set to 2 and not 0 in the while loop?

byevrolex
visit shbcf.ru