This is actually an accurate representation of recursion i have seen some people do both recursive calls in a single one in the explanation of recursion when in reality the function keeps calling itself until the base case is finished and then call the next function in the same stack frame which then unwinds into the previous stack frame which then calls the next function in that stack frame. this is actually a good resource on learning recursion.
So underrated this video! As a visual learner I need to understand how everything works in order for me to say I truly understand it instead of just sounding smart and saying I do. I understand recursion and its function stack with backtracking now. Keep up the awesome work. Other tutorials suck on this.
I have a question, why we are not doing F(5) = F(4) + F(3) at the same time, F(4) = F(3) + F(2), F(3) = F(2) + F(1) , instead we find F(4) first and then start find F(3)
I’ll try my best to explain this. That’s a stack. So it’s going to be depth first by nature. Inside F(4), the instruction says that it should calculate F(3). So it steps in for calculating F(3). But inside F(3), the instruction to calculate F(2) is encountered first. So the program goes to calculate that. And so on. And backtraces the value to F(4) then has the instruction to calculate F(3). Goes in and comes back. And only after that does it perform the addition. I omitted the additions that happen inside each call. But I hope this gives you a better insight as to why it is the case?
I don't get the part at 3:19 Once fib(2) returned 1+0. How is it going back up ? Isn't it supposed to stop the function once it returned something ? How is fib(3) receiving the value returned by fib(2) ? Basically i don't really get how it's going back up once it returned something. Btw thanks for the video it was great, i am starting to gasp recursion a bit.
Just like any other function returns and the control goes back to the function where it was called from. You call printf from main, it does its job, control comes back to main and then the rest of the main function is executed. In recursion, it’s no different. fib called fib, fib did its job (calling other fibs), the control returned back to fib (which might again call another fib). This might actually require a follow up video, which I think would be beneficial for others having similar questions.
@@theteachr Oh yeah now i get it. fib(3) fib(4) and fib(5) didn't dissapear they are still there waiting for the response of their child functions that are being executed.
@@theteachr Thanks for quick reply sir. I I thought same steps will be followed similar like this(ruclips.net/video/wDRqYrxTySc/видео.html). inside fib4 fib ruclips.net/video/wDRqYrxTySc/видео.html 2 + fib(2) I thought it will again call fib2 and after the condition is false then fib2 will become fib0 and it will return 0
This is actually an accurate representation of recursion i have seen some people do both recursive calls in a single one in the explanation of recursion when in reality the function keeps calling itself until the base case is finished and then call the next function in the same stack frame which then unwinds into the previous stack frame which then calls the next function in that stack frame. this is actually a good resource on learning recursion.
This is honestly an underrated RUclips channel I also love how everything is in c
it's not underrated... it has not been rated yet. :) keep up the good work @theteachr
Thank you a lot , the other youtubers didn't explain as well as you for me
Fantastic explanation, the graphics and animations really help
So underrated this video! As a visual learner I need to understand how everything works in order for me to say I truly understand it instead of just sounding smart and saying I do. I understand recursion and its function stack with backtracking now. Keep up the awesome work. Other tutorials suck on this.
I have a question, why we are not doing F(5) = F(4) + F(3) at the same time, F(4) = F(3) + F(2), F(3) = F(2) + F(1) , instead we find F(4) first and then start find F(3)
I’ll try my best to explain this. That’s a stack. So it’s going to be depth first by nature. Inside F(4), the instruction says that it should calculate F(3). So it steps in for calculating F(3). But inside F(3), the instruction to calculate F(2) is encountered first. So the program goes to calculate that. And so on. And backtraces the value to F(4) then has the instruction to calculate F(3). Goes in and comes back. And only after that does it perform the addition. I omitted the additions that happen inside each call. But I hope this gives you a better insight as to why it is the case?
Damn this video satisfied my soul
Thank you for explanation!
I wish our professor could have explained this in 4:57 mins. Thank you so much!
I don't get the part at 3:19
Once fib(2) returned 1+0. How is it going back up ? Isn't it supposed to stop the function once it returned something ?
How is fib(3) receiving the value returned by fib(2) ?
Basically i don't really get how it's going back up once it returned something.
Btw thanks for the video it was great, i am starting to gasp recursion a bit.
Just like any other function returns and the control goes back to the function where it was called from. You call printf from main, it does its job, control comes back to main and then the rest of the main function is executed. In recursion, it’s no different. fib called fib, fib did its job (calling other fibs), the control returned back to fib (which might again call another fib).
This might actually require a follow up video, which I think would be beneficial for others having similar questions.
@@theteachr Oh yeah now i get it. fib(3) fib(4) and fib(5) didn't dissapear they are still there waiting for the response of their child functions that are being executed.
Underrated channel
What software did you use to make the animations?
Keynote
Incredible explanation my friend
Helped me a lot. Thank you.
wow. amazing. explained so easily.
Thank you very much !!! :)
you are the best
Why fib2 inside fib4 return 1 it should return 0
Irrespective of from where it’s called, fib(2) will always return 1. Why do you think it should return a zero?
@@theteachr Thanks for quick reply sir. I I thought same steps will be followed similar like this(ruclips.net/video/wDRqYrxTySc/видео.html).
inside fib4 fib ruclips.net/video/wDRqYrxTySc/видео.html
2 + fib(2)
I thought it will again call fib2 and after the condition is false then fib2 will become fib0 and it will return 0
Request you to reply