Stepping Through Recursive Fibonacci Function

Sdílet
Vložit
  • čas přidán 29. 06. 2011
  • Understanding why and how the recursive Fibonacci function works

Komentáře • 246

  • @yanzeliu
    @yanzeliu Před 9 lety +287

    This is the most clear explanation I found !! It's really nice and helpful.

  • @marybandziukas1544
    @marybandziukas1544 Před 4 lety +24

    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.

  • @user-mn3iq2cs9n
    @user-mn3iq2cs9n Před 4 lety +16

    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!!!

  • @julietonyekaoha402
    @julietonyekaoha402 Před 4 lety +1

    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.

  • @mr.anonymous6098
    @mr.anonymous6098 Před 2 lety

    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!

  • @ikroac
    @ikroac Před rokem

    13 years after and this explanation of recursive function is still the better. Thanks a lot sir

  • @max-pax
    @max-pax Před 3 lety +29

    I loved it. Most productive 5 minutes of my life right after conception and birth :)

  • @alexandrafoot8783
    @alexandrafoot8783 Před 3 lety

    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

  • @amitdhawan579
    @amitdhawan579 Před 3 lety +1

    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!

  • @basedmangoes3379
    @basedmangoes3379 Před 8 lety +3

    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.

  • @SrFrancia0
    @SrFrancia0 Před 9 měsíci

    Very good explanation. Amazing that this video is 12 years and there isn't a newer one that explains it better

  • @Occupiedmarkus
    @Occupiedmarkus Před rokem +2

    11 years later, this is still the better video than the rest

  • @abdulhk79
    @abdulhk79 Před 2 měsíci

    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.

  • @ozzyfromspace
    @ozzyfromspace Před 5 lety +2

    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!

  • @andrewfrolov5144
    @andrewfrolov5144 Před 4 měsíci

    Best explanation ever, even math websites couldn't get to the point what it really wants. Perfect!

  • @jra89027
    @jra89027 Před 2 lety

    This is a really good example of what is actually going on during recursion. Thank you!

  • @sidd8988
    @sidd8988 Před 4 lety

    I was searching for an hour to find a best explanation for a recursive function. Finally ended by here ☺️

  • @cartylove3829
    @cartylove3829 Před 4 měsíci

    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 👍

  • @Sarah-re7cg
    @Sarah-re7cg Před 2 lety

    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.

  • @manish436
    @manish436 Před 2 lety +1

    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....

  • @usraniguugl
    @usraniguugl Před 9 lety +1

    Sir, THANK YOU VERY MUCH!! it's not only in knowing something but in the ability to explain it! great video!

  • @tabula.rasa.
    @tabula.rasa. Před 5 měsíci

    I've been struggling with this for week and this is literally the only video that cleared it up.

  • @anilbarad1856
    @anilbarad1856 Před 2 lety +2

    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.

  • @yusufgokce7524
    @yusufgokce7524 Před 3 lety +1

    The code up there is probably the most beautiful thing I've ever seen

  • @zubairhasan9434
    @zubairhasan9434 Před 2 lety

    THE BEST EXPLANATION!! I've been pulling my hair off how th does this recursive call works internally. Now I've finally got it.

  • @AbhishekDubeyIT
    @AbhishekDubeyIT Před 5 lety +2

    Thank you very much,I am from India, I loved the way you solved it as easy as possible. thanx again

  • @daneeldouglass6391
    @daneeldouglass6391 Před 6 lety +1

    THIS IS THE MOST BEAUTIFUL EXAMPLE OF PROGRAMMING AND RECURSION!! With this example alone i have became a better programmer.

  • @baabujatin
    @baabujatin Před 4 lety +1

    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.

  • @MegaEriable
    @MegaEriable Před 12 lety

    SAL, YOU ROCK! I JUST CAN'T DESCRIBE HOW HELPFUL THIS VIDEO WAS TO ME! THANK YOU SO SO MUCH!

  • @martingracchus1687
    @martingracchus1687 Před 3 lety +3

    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)

    • @MiMachoAlQueLeChupoLaVerga
      @MiMachoAlQueLeChupoLaVerga Před 8 měsíci

      It´s funny what you are saying, because currently the software development industry is full of "programmers" which lack of fundamentals and propper preparation.

  • @mitchellstevens3948
    @mitchellstevens3948 Před 7 lety +5

    THANK YOU! I've been looking for this explanation in preparation for a tech interview, for WEEKS!

  • @KDazee
    @KDazee Před 8 lety +73

    You are really a life saver sir. Your explanation was so clear I understood it in one try. Thank you

    • @csnick248
      @csnick248 Před 7 lety +2

      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. :)

    • @rajivnarayan5214
      @rajivnarayan5214 Před 7 lety

      Thats y you gotta program a lot. You'll realise when to and when not to use it.

    • @aiueo8962
      @aiueo8962 Před rokem

      ​@@csnick248i agree with you

    • @jmbrjmbr2397
      @jmbrjmbr2397 Před 6 měsíci

      @@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)

  • @HarishSm-g6s
    @HarishSm-g6s Před 24 dny

    You're just Amazing dude!!! Perfect Video to understand sum of multiple recursive functions.

  • @HJ-vk2bq
    @HJ-vk2bq Před 3 lety

    This is the clearest explanation I have ever seen. very helpful

  • @pradeenkrishnag2368
    @pradeenkrishnag2368 Před rokem +1

    Best explanation. Was trying to figure out. Now it is clear.

  • @haddly123
    @haddly123 Před 7 lety +19

    awesome, awesome video. Have been trying to understand why fib(4) + fib(3) doesn't equal 7. You explained perfectly. Cheers

  • @itstaw
    @itstaw Před 6 měsíci

    Thank you lol Much clearer and more precise than other explanations I have found!

  • @MuwalJitender
    @MuwalJitender Před 2 lety

    Bravo Khan Academy. You are doing awesome work.

  • @sheldonwalkerjr8210
    @sheldonwalkerjr8210 Před 5 lety +1

    Thank you sooo much! I could not wrap my head around this.

  • @CrazyTimeTraveler
    @CrazyTimeTraveler Před 6 lety +2

    Thank you very much for this very clear explanation, this might save me for my test tomorrow :D

  • @Arif_0899
    @Arif_0899 Před 3 lety +2

    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.

  • @irfanbabar8424
    @irfanbabar8424 Před 4 měsíci

    Simple & clear explanation. Thanks

  • @spacemeter3001
    @spacemeter3001 Před 4 lety

    Perfect video. Understood it right away. You're better than my teacher in programming. lmao

  • @astroboomboy
    @astroboomboy Před 11 lety +1

    Very nice explanation of a compiler. Easy and clear!

  • @BriteRoy
    @BriteRoy Před 11 lety +2

    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

  • @ammgnero
    @ammgnero Před 3 lety

    Holy Moly
    wonderful explanation sir

  • @ronglass5968
    @ronglass5968 Před 7 lety +2

    Beautifully explained. Thank you!

  • @gurkiratsingh9788
    @gurkiratsingh9788 Před 5 lety +1

    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)

  • @aliahmed-lj4rb
    @aliahmed-lj4rb Před rokem

    The simplest and subtle explanation on entire youtube

  • @pascal3719
    @pascal3719 Před 3 lety +1

    Greetings everyone, Please does anyone know any textbook that has practice problems on Fibonacci sequence, mathematical Induction and recursive?

  • @felipelima2724
    @felipelima2724 Před 4 lety +2

    Very good explanation!!! The best!

  • @affanzama8280
    @affanzama8280 Před 4 měsíci

    should that not return fin(2) as 2 ?
    because 2

  • @AnaGuerra03
    @AnaGuerra03 Před 2 lety +1

    THANK YOU
    THANK YOU
    THANK YOU
    THANK YOU
    THANK YOU

  • @TimmyGoesForTrip
    @TimmyGoesForTrip Před 4 lety +1

    gosh that was the best to video to understand the sequence! thank you from 2020)

  • @saicharancherry3266
    @saicharancherry3266 Před 7 lety

    is first left tree **fibonacci(n-1) or right tree **fibonacci(n-2) or both at a time are construced.......?

  • @funmathematics58
    @funmathematics58 Před 3 lety +1

    Best explanation of fibonacci on youtube!

  • @martinmoragab
    @martinmoragab Před 2 lety

    Amazing explanation! Easy to understand it this way. Thanks!

  • @DrDerivative
    @DrDerivative Před 2 lety

    Exactly what I needed to understand this topic, thank you!

  • @daltonistadod2855
    @daltonistadod2855 Před 2 měsíci +1

    I needed that so badly

  • @ngxbeans
    @ngxbeans Před 11 lety

    Usually rely on Khan's videos for math help. Now I have his help with CPU SCI. Very happy right now lol

  • @AdnanRizvan
    @AdnanRizvan Před 9 lety

    Very helpful indeed.You explain a lot better than professor and it really helped me figure out how does this actually work. +1

  • @baryosef6245
    @baryosef6245 Před 7 lety

    Amazing explanation. You are awesome!

  • @dynamicdkl
    @dynamicdkl Před 2 lety

    there will be so many return values , how are we getting perticular value . please explain

  • @avichiii
    @avichiii Před 11 měsíci

    one of the most clear explanation.

  • @abdallahelnashar1520
    @abdallahelnashar1520 Před rokem

    Wooooow Thank you very much Greatest Explanation Ever!!!

  • @yadatis5905
    @yadatis5905 Před 5 lety +1

    Thank you so much ☺️ sir. It's very helpful for me.

  • @Nasimkhadv1996
    @Nasimkhadv1996 Před rokem

    Thank you so much for your clear explanation. This helped me a lot🤩

  • @voltron909
    @voltron909 Před 11 lety

    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.

  • @markkillion6845
    @markkillion6845 Před rokem

    Thank you for this clear explanation. It was very helpful!

  • @danielarista1352
    @danielarista1352 Před 8 měsíci +1

    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).

  • @FromTheV
    @FromTheV Před 5 měsíci

    Absolutely perfect! Thank you

  • @noncreativenickname2
    @noncreativenickname2 Před 11 lety

    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?

  • @ansekao4516
    @ansekao4516 Před 2 lety

    WOW, thank you very much, bc I wasn't sure I was assuming it correctly. Thank you very much for making it clear. ;3

  • @min_808
    @min_808 Před 10 měsíci

    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

  • @cedricmendoza8316
    @cedricmendoza8316 Před 3 lety

    Always quality content. Thank you.

  • @rzzldzzl8410
    @rzzldzzl8410 Před 4 měsíci

    but the 5th Fibonacci number is 3, so I dont understand where is it? Why did it return 5 back??

  • @vishnu364
    @vishnu364 Před 3 lety

    simple and neat explanation...thanks a ton!!

  • @lestra378
    @lestra378 Před 2 lety

    Thank you for this amazing explanation

  • @andregomes7232
    @andregomes7232 Před 2 lety

    Thank you so much man! you made it looks easy

  • @cellmaker1
    @cellmaker1 Před 2 lety

    This is extremely helpful. Thanks

  • @92501le386
    @92501le386 Před 3 lety

    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.

  • @bradleonn
    @bradleonn Před 13 dny

    THANK YOU! This helped me finally understand how it was working

  • @PratikDeshmane7006
    @PratikDeshmane7006 Před 5 lety +2

    Finally got the perfect explanation!

  • @trippyvoyager9879
    @trippyvoyager9879 Před 4 lety

    This is the best video i found on the internet

  • @codaacademy5888
    @codaacademy5888 Před 7 měsíci

    this is the best explanation , really thanks

  • @zenlupe
    @zenlupe Před 8 lety +2

    Great explanation!

  • @ravipatel-xu5qi
    @ravipatel-xu5qi Před 3 lety

    Thank you for your efforts.

  • @lesegomabe2679
    @lesegomabe2679 Před 9 lety

    Great explanation! Thank you!

  • @nikosspiropoulos8417
    @nikosspiropoulos8417 Před 2 lety

    wow dude, you are awesome! thank you so much!

  • @yogi915.
    @yogi915. Před 7 lety

    So thankful for your explanation!

  • @christanprice5720
    @christanprice5720 Před rokem

    This was extremely helpful!

  • @anyavailablehandle
    @anyavailablehandle Před 2 lety

    Great explanation !!! Thanks

  • @FredMaher
    @FredMaher Před 9 měsíci

    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.

  • @ars7070
    @ars7070 Před 5 lety

    TQ soooooo much... Uve help me ony exam day

  • @mink9048
    @mink9048 Před 4 lety

    Great video. Thank you.

  • @yagnapatel3912
    @yagnapatel3912 Před 3 lety

    Everything makes sense now, much thanks

  • @himanshusaxena8639
    @himanshusaxena8639 Před rokem

    This video would have saved my week if I found it earlier .

  • @himashihettegedona9484
    @himashihettegedona9484 Před 5 lety +1

    Thank you so much for this video!

  • @zacloebs
    @zacloebs Před rokem

    First video that made me actually understand :)

  • @DietrichG
    @DietrichG Před 9 lety

    Very nicely explained, however performance wise this is very intensive.