Thank you! I have been puzzling over how this works for 2 days. Khan Academy always delivers a clear and completely understandable explanation. Mainly by use of colors and not skipping a single step.
This is the ONLY clear, clean, and thorough explanation of this algorithm, that I've found, on youtube or EdX. Thanks a million. You make it a good thing to shout KHAAAAAAAAAAAAAAN!!!
I have been going over the recursive solution of the Fibonacci sequence for a day now and I couldn't figure it out , this explanation was clear and concise and I finally understood what is happening under the hood. Thank you so much.
Wow! This guy knows so much about so many things. I am truly impressed! Khan, you are a lifesaver! Watched your videos for almost every AP class that I took in High School. Now I am in college and still keep watching your videos cuz they are really helpful!
I went over my class notes on recursion several times and it just wasn't clicking, then 2:08 minutes into this video I suddenly get it like its as simple as 2+2. You are a skilled teacher and a gift to the world
Amazing explanation Sal. I have looked through many videos that explained how to trace a recursive function with two calls in one method, and this one really takes the cake.
I did try to understand this for almost an hour. Not for this video, I really don't know how much more time was needed to figure this out. This explanation will further help me to unpack other programming aspects. Thanks a lot.
The mind bending thing about writing recursive code is the realization that all you’re doing is writing one function that returns a second function. The eureka moment comes when you realize that the second function could be anything, and in this case it is the starting function, perhaps with an algorithmically deprecated or advanced parameter. Then those base cases just show up to stop the code from running ‘forever’ (i.e. until your processor crashes). In a way, recursion is a way of nesting functions, and sure the values at each step have to be stored on the stack and there’s a whole bunch of clever stuff happening in the background, but essentially a recursion is when you write a program that calls itself later, in effect allowing you to build a loop of functions. I can totally see how this would be useful for generating trees and other linked data structures. Thanks for the explanation, Sal! When I was first exposed to recursive code in my freshman year, I didn’t understand it and I failed to see the relevance but now it seems more natural. Kudos to you sir, learning never stops!
Man I wished I watched this video before doing my coding assignment, but I’m still glad I watched it because i was not able to figure it out during my assignment, and it bothered me so much afterwards. Can’t believe I never understood how Fibonacci works until now, good video 👍
This is very clean and clear to visualize. Our mind do not work on numbers/text, it works on visualizations/images This how we would be thing about recursion in our mind. Thanks a lot for understanding our mind & making us understand too....
Awesome Stuff.. Most clear as mentioned by others.. took me around 10 videos to land here... was not able to understand the concept ... Thanks Team ... Stay blessed.
amazing, for 9 years this video has been granting clarification to aspiring programmers. I am learning how to use caching and hashtables to reduce the time complexity of this function but did not fully understand how the naive solution worked and how the stack handles all of the returned values and how they are actually added. this makes so much sense now, THANKS. "The cobwebs are now removed" - artie bucco (anyone who gets this reference gets a like)
It´s funny what you are saying, because currently the software development industry is full of "programmers" which lack of fundamentals and propper preparation.
Actually, when solving the fibonacci problem - or more importantly recursive problems in general - we don't think in this way at all. We think about it in a pretty much mathematical way and apply the "recursive leap of faith"; that is, we assume that it works, ignore all the fuzzy details and let the computer deal with those. We only focus at one single level of computation; if we have found the base cases, have managed to break down the problem into smaller instances of the same form, solved those and combined them, then the algorithm will simply work. Perhaps you meant this. :)
@@csnick248 yes but imagine this, what if they ask you the runtime of this problem? How are you going to calculate the steps this function takes? You need a deeper understanding of computer's control flow to calculate that (big O)
WoW.... I promise you once I become a software engineer, I will donate half of my first salary to khan academy and that's a promise. You really are changing lives.
Omg , I was seriously baffled with recursive function's backend process since last few days and finally my doubt is (I think) clear ,basically it remembers the values in a stack and processes step by step. Now hopefully I'll be able to solve a similar recursive question.Thanks khanacademy
Compilers are used to interpret computer language (english word commands) into machine language (binary language such as 010101). Machine language are what processors use to carry out what you want. A compiler takes some function, and converts it to machine language.
Note: The fifth number in the Fibonacci sequence is 5. It's is coincidence that the 5th number is 5. The 6th number in the sequence is 8. Because adding the 4th value (3) and 5th value (5) results in 8 (the sixth value).
Can anyone hint me on how MIPS manages the stack on recursive functions? How the stack pointer gets all the way up to the top of the stack when finally the true in the procedure is returned?
I think it was helpful to know that the Fibonacci sequence is computed by looking at the previous two numbers and adding them. This recursive statement works by subtracting each number from the one before, and two before and adding them together. Tracing the steps was very useful though
thank you very clear explanation you have a gift, man what a talent you have thank you for taking the time to do this, its helping so many out there i do believe.
I have been trying to find something that actually explains how recursion works. In this case using a fibonacci sequence, it is clearly explained. I had been thinking about it all wrong - It was the tree structure that helped me understand it once and for all. Chat GPT and BARD were no help at all. I am now smarter than I was 8 minutes ago.
This is the most clear explanation I found !! It's really nice and helpful.
I think it's horrible for the simple fact that it doesn't mention the stack.
yeah!!!!!
TILL THIS DAY
Yes bro
@@redrowolloftnod5230 after going through some recursion , i felt its working like stack . isn't it ?
Thank you! I have been puzzling over how this works for 2 days. Khan Academy always delivers a clear and completely understandable explanation. Mainly by use of colors and not skipping a single step.
This is the ONLY clear, clean, and thorough explanation of this algorithm, that I've found, on youtube or EdX. Thanks a million. You make it a good thing to shout KHAAAAAAAAAAAAAAN!!!
I have been going over the recursive solution of the Fibonacci sequence for a day now and I couldn't figure it out , this explanation was clear and concise and I finally understood what is happening under the hood. Thank you so much.
Wow! This guy knows so much about so many things. I am truly impressed! Khan, you are a lifesaver! Watched your videos for almost every AP class that I took in High School. Now I am in college and still keep watching your videos cuz they are really helpful!
13 years after and this explanation of recursive function is still the better. Thanks a lot sir
I loved it. Most productive 5 minutes of my life right after conception and birth :)
I went over my class notes on recursion several times and it just wasn't clicking, then 2:08 minutes into this video I suddenly get it like its as simple as 2+2. You are a skilled teacher and a gift to the world
I have watched quite a few videos on recursion but this one has explained it clearest of all. Thank you very much for this awesomeness!
Amazing explanation Sal. I have looked through many videos that explained how to trace a recursive function with two calls in one method, and this one really takes the cake.
Very good explanation. Amazing that this video is 12 years and there isn't a newer one that explains it better
11 years later, this is still the better video than the rest
I did try to understand this for almost an hour. Not for this video, I really don't know how much more time was needed to figure this out. This explanation will further help me to unpack other programming aspects. Thanks a lot.
The mind bending thing about writing recursive code is the realization that all you’re doing is writing one function that returns a second function. The eureka moment comes when you realize that the second function could be anything, and in this case it is the starting function, perhaps with an algorithmically deprecated or advanced parameter. Then those base cases just show up to stop the code from running ‘forever’ (i.e. until your processor crashes). In a way, recursion is a way of nesting functions, and sure the values at each step have to be stored on the stack and there’s a whole bunch of clever stuff happening in the background, but essentially a recursion is when you write a program that calls itself later, in effect allowing you to build a loop of functions. I can totally see how this would be useful for generating trees and other linked data structures. Thanks for the explanation, Sal! When I was first exposed to recursive code in my freshman year, I didn’t understand it and I failed to see the relevance but now it seems more natural. Kudos to you sir, learning never stops!
Best explanation ever, even math websites couldn't get to the point what it really wants. Perfect!
This is a really good example of what is actually going on during recursion. Thank you!
I was searching for an hour to find a best explanation for a recursive function. Finally ended by here ☺️
Man I wished I watched this video before doing my coding assignment, but I’m still glad I watched it because i was not able to figure it out during my assignment, and it bothered me so much afterwards. Can’t believe I never understood how Fibonacci works until now, good video 👍
This is extremely helpful. I got so caught up and confused on how to trace where in the world the interpreter is. thank you so much.
This is very clean and clear to visualize.
Our mind do not work on numbers/text, it works on visualizations/images
This how we would be thing about recursion in our mind. Thanks a lot for understanding our mind & making us understand too....
Sir, THANK YOU VERY MUCH!! it's not only in knowing something but in the ability to explain it! great video!
I've been struggling with this for week and this is literally the only video that cleared it up.
i have seen too many videos on this but this video has best explanation ever , great video , i am going to press subscribe button...thank you.
The code up there is probably the most beautiful thing I've ever seen
THE BEST EXPLANATION!! I've been pulling my hair off how th does this recursive call works internally. Now I've finally got it.
Thank you very much,I am from India, I loved the way you solved it as easy as possible. thanx again
THIS IS THE MOST BEAUTIFUL EXAMPLE OF PROGRAMMING AND RECURSION!! With this example alone i have became a better programmer.
Awesome Stuff.. Most clear as mentioned by others.. took me around 10 videos to land here... was not able to understand the concept ... Thanks Team ... Stay blessed.
SAL, YOU ROCK! I JUST CAN'T DESCRIBE HOW HELPFUL THIS VIDEO WAS TO ME! THANK YOU SO SO MUCH!
amazing, for 9 years this video has been granting clarification to aspiring programmers. I am learning how to use caching and hashtables to reduce the time complexity of this function but did not fully understand how the naive solution worked and how the stack handles all of the returned values and how they are actually added. this makes so much sense now, THANKS.
"The cobwebs are now removed" - artie bucco (anyone who gets this reference gets a like)
It´s funny what you are saying, because currently the software development industry is full of "programmers" which lack of fundamentals and propper preparation.
THANK YOU! I've been looking for this explanation in preparation for a tech interview, for WEEKS!
You are really a life saver sir. Your explanation was so clear I understood it in one try. Thank you
Actually, when solving the fibonacci problem - or more importantly recursive problems in general - we don't think in this way at all. We think about it in a pretty much mathematical way and apply the "recursive leap of faith"; that is, we assume that it works, ignore all the fuzzy details and let the computer deal with those. We only focus at one single level of computation; if we have found the base cases, have managed to break down the problem into smaller instances of the same form, solved those and combined them, then the algorithm will simply work. Perhaps you meant this. :)
Thats y you gotta program a lot. You'll realise when to and when not to use it.
@@csnick248i agree with you
@@csnick248 yes but imagine this, what if they ask you the runtime of this problem? How are you going to calculate the steps this function takes? You need a deeper understanding of computer's control flow to calculate that (big O)
You're just Amazing dude!!! Perfect Video to understand sum of multiple recursive functions.
This is the clearest explanation I have ever seen. very helpful
Best explanation. Was trying to figure out. Now it is clear.
awesome, awesome video. Have been trying to understand why fib(4) + fib(3) doesn't equal 7. You explained perfectly. Cheers
@Juan2003gtr ?
Exactly. This is what I also did not understand
Thank you lol Much clearer and more precise than other explanations I have found!
Bravo Khan Academy. You are doing awesome work.
Thank you sooo much! I could not wrap my head around this.
Thank you very much for this very clear explanation, this might save me for my test tomorrow :D
WoW.... I promise you once I become a software engineer, I will donate half of my first salary to khan academy and that's a promise. You really are changing lives.
Simple & clear explanation. Thanks
Perfect video. Understood it right away. You're better than my teacher in programming. lmao
Very nice explanation of a compiler. Easy and clear!
Omg , I was seriously baffled with recursive function's backend process since last few days and finally my doubt is (I think) clear ,basically it remembers the values in a stack and processes step by step. Now hopefully I'll be able to solve a similar recursive question.Thanks khanacademy
Holy Moly
wonderful explanation sir
Beautifully explained. Thank you!
is it legal to write fibonacci(3) with fibonacci(4) coz the fibonacci(4) will be called first before evaluating the parameter of ffibonacci(3)
The simplest and subtle explanation on entire youtube
Greetings everyone, Please does anyone know any textbook that has practice problems on Fibonacci sequence, mathematical Induction and recursive?
Very good explanation!!! The best!
should that not return fin(2) as 2 ?
because 2
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
gosh that was the best to video to understand the sequence! thank you from 2020)
is first left tree **fibonacci(n-1) or right tree **fibonacci(n-2) or both at a time are construced.......?
Best explanation of fibonacci on youtube!
Amazing explanation! Easy to understand it this way. Thanks!
Exactly what I needed to understand this topic, thank you!
I needed that so badly
Usually rely on Khan's videos for math help. Now I have his help with CPU SCI. Very happy right now lol
Very helpful indeed.You explain a lot better than professor and it really helped me figure out how does this actually work. +1
Amazing explanation. You are awesome!
there will be so many return values , how are we getting perticular value . please explain
one of the most clear explanation.
Wooooow Thank you very much Greatest Explanation Ever!!!
Thank you so much ☺️ sir. It's very helpful for me.
Thank you so much for your clear explanation. This helped me a lot🤩
Compilers are used to interpret computer language (english word commands) into machine language (binary language such as 010101). Machine language are what processors use to carry out what you want. A compiler takes some function, and converts it to machine language.
Thank you for this clear explanation. It was very helpful!
Note: The fifth number in the Fibonacci sequence is 5. It's is coincidence that the 5th number is 5. The 6th number in the sequence is 8. Because adding the 4th value (3) and 5th value (5) results in 8 (the sixth value).
Absolutely perfect! Thank you
Can anyone hint me on how MIPS manages the stack on recursive functions? How the stack pointer gets all the way up to the top of the stack when finally the true in the procedure is returned?
WOW, thank you very much, bc I wasn't sure I was assuming it correctly. Thank you very much for making it clear. ;3
I think it was helpful to know that the Fibonacci sequence is computed by looking at the previous two numbers and adding them. This recursive statement works by subtracting each number from the one before, and two before and adding them together. Tracing the steps was very useful though
Always quality content. Thank you.
but the 5th Fibonacci number is 3, so I dont understand where is it? Why did it return 5 back??
simple and neat explanation...thanks a ton!!
Thank you for this amazing explanation
Thank you so much man! you made it looks easy
This is extremely helpful. Thanks
thank you very clear explanation you have a gift, man what a talent you have thank you for taking the time to do this, its helping so many out there i do believe.
THANK YOU! This helped me finally understand how it was working
Finally got the perfect explanation!
This is the best video i found on the internet
this is the best explanation , really thanks
Great explanation!
Thank you for your efforts.
Great explanation! Thank you!
wow dude, you are awesome! thank you so much!
So thankful for your explanation!
This was extremely helpful!
Great explanation !!! Thanks
I have been trying to find something that actually explains how recursion works. In this case using a fibonacci sequence, it is clearly explained. I had been thinking about it all wrong - It was the tree structure that helped me understand it once and for all. Chat GPT and BARD were no help at all. I am now smarter than I was 8 minutes ago.
TQ soooooo much... Uve help me ony exam day
Great video. Thank you.
Everything makes sense now, much thanks
This video would have saved my week if I found it earlier .
Thank you so much for this video!
First video that made me actually understand :)
Very nicely explained, however performance wise this is very intensive.