Stepping Through Recursive Fibonacci Function

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ก.พ. 2025

ความคิดเห็น • 250

  • @yanzeliu
    @yanzeliu 9 ปีที่แล้ว +306

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

    • @redrowolloftnod5230
      @redrowolloftnod5230 7 ปีที่แล้ว +5

      I think it's horrible for the simple fact that it doesn't mention the stack.

    • @joemah555
      @joemah555 6 ปีที่แล้ว

      yeah!!!!!

    • @jose-fi3gw
      @jose-fi3gw 4 ปีที่แล้ว

      TILL THIS DAY

    • @manmohanchowdary1707
      @manmohanchowdary1707 3 ปีที่แล้ว

      Yes bro

    • @dynamicdkl
      @dynamicdkl 3 ปีที่แล้ว

      @@redrowolloftnod5230 after going through some recursion , i felt its working like stack . isn't it ?

  • @marybandziukas1544
    @marybandziukas1544 5 ปีที่แล้ว +33

    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.

  • @陈瀚龙
    @陈瀚龙 5 ปีที่แล้ว +24

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

  • @anfrollex
    @anfrollex 10 หลายเดือนก่อน +2

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

  • @KDazee
    @KDazee 9 ปีที่แล้ว +77

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

    • @csnick248
      @csnick248 8 ปีที่แล้ว +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 8 ปีที่แล้ว

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

    • @aiueo8962
      @aiueo8962 ปีที่แล้ว

      ​@@csnick248i agree with you

    • @jmbrjmbr000
      @jmbrjmbr000 ปีที่แล้ว

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

  • @julietonyekaoha402
    @julietonyekaoha402 4 ปีที่แล้ว +2

    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.

  • @max-pax
    @max-pax 4 ปีที่แล้ว +31

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

  • @martingracchus1687
    @martingracchus1687 4 ปีที่แล้ว +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)

  • @anilbarad1856
    @anilbarad1856 2 ปีที่แล้ว +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.

  • @alexandrafoot8783
    @alexandrafoot8783 4 ปีที่แล้ว

    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

  • @nikkyujoshi
    @nikkyujoshi 4 หลายเดือนก่อน

    This guy is the one of the best teacher in the world. With little touch of real humour in teaching, students could learn almost anything without any stress.

  • @Occupiedmarkus
    @Occupiedmarkus 2 ปีที่แล้ว +2

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

  • @ozzyfromspace
    @ozzyfromspace 6 ปีที่แล้ว +3

    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!

  • @ikroac
    @ikroac ปีที่แล้ว

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

  • @basedmangoes3379
    @basedmangoes3379 9 ปีที่แล้ว +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.

  • @amitdhawan579
    @amitdhawan579 4 ปีที่แล้ว +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!

  • @abdulhk79
    @abdulhk79 9 หลายเดือนก่อน

    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.

  • @manish436
    @manish436 3 ปีที่แล้ว +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....

  • @SrFrancia0
    @SrFrancia0 ปีที่แล้ว

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

  • @AnaGuerra03
    @AnaGuerra03 3 ปีที่แล้ว +1

    THANK YOU
    THANK YOU
    THANK YOU
    THANK YOU
    THANK YOU

  • @haddly123
    @haddly123 7 ปีที่แล้ว +19

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

  • @itsmeccc
    @itsmeccc 11 หลายเดือนก่อน

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

  • @mr.anonymous6098
    @mr.anonymous6098 3 ปีที่แล้ว

    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!

  • @zubairhasan9434
    @zubairhasan9434 2 ปีที่แล้ว

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

  • @cartylove3829
    @cartylove3829 11 หลายเดือนก่อน

    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 👍

  • @noah_ayyubi
    @noah_ayyubi 3 หลายเดือนก่อน

    Nobody explained it like this bro well done best video on yt

  • @nohandleid
    @nohandleid 4 ปีที่แล้ว +1

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

  • @sidd8988
    @sidd8988 4 ปีที่แล้ว

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

  • @pradeenkrishnag2368
    @pradeenkrishnag2368 2 ปีที่แล้ว +1

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

  • @daltonistadod2855
    @daltonistadod2855 8 หลายเดือนก่อน +1

    I needed that so badly

  • @itstaw
    @itstaw ปีที่แล้ว

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

  • @funmathematics58
    @funmathematics58 3 ปีที่แล้ว +1

    Best explanation of fibonacci on youtube!

  • @AbhishekDubeyIT
    @AbhishekDubeyIT 6 ปีที่แล้ว +2

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

  • @daneeldouglass6391
    @daneeldouglass6391 7 ปีที่แล้ว +1

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

  • @mitchellstevens3948
    @mitchellstevens3948 7 ปีที่แล้ว +5

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

  • @HJ-vk2bq
    @HJ-vk2bq 3 ปีที่แล้ว

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

  • @BriteRoy
    @BriteRoy 12 ปีที่แล้ว +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

  • @usraniguugl
    @usraniguugl 10 ปีที่แล้ว +1

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

  • @jra89027
    @jra89027 3 ปีที่แล้ว

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

  • @baabujatin
    @baabujatin 4 ปีที่แล้ว +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.

  • @Sarah-re7cg
    @Sarah-re7cg 3 ปีที่แล้ว

    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.

  • @aliahmed-lj4rb
    @aliahmed-lj4rb ปีที่แล้ว

    The simplest and subtle explanation on entire youtube

  • @spacemeter3001
    @spacemeter3001 5 ปีที่แล้ว

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

  • @MegaEriable
    @MegaEriable 13 ปีที่แล้ว

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

  • @HarishSm-g6s
    @HarishSm-g6s 7 หลายเดือนก่อน

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

  • @Arif_0899
    @Arif_0899 3 ปีที่แล้ว +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.

  • @TimmyGoesForTrip
    @TimmyGoesForTrip 4 ปีที่แล้ว +1

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

  • @CrazyTimeTraveler
    @CrazyTimeTraveler 6 ปีที่แล้ว +2

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

  • @trippyvoyager9879
    @trippyvoyager9879 4 ปีที่แล้ว

    This is the best video i found on the internet

  • @sheldonwalkerjr8210
    @sheldonwalkerjr8210 5 ปีที่แล้ว +1

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

  • @astroboomboy
    @astroboomboy 12 ปีที่แล้ว +1

    Very nice explanation of a compiler. Easy and clear!

  • @DigipreneurIdeas
    @DigipreneurIdeas 4 หลายเดือนก่อน

    I wished I fond this video cause I spent soo many hours trying to understand this. Thank you

  • @MuwalJitender
    @MuwalJitender 3 ปีที่แล้ว

    Bravo Khan Academy. You are doing awesome work.

  • @ngxbeans
    @ngxbeans 11 ปีที่แล้ว

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

  • @irfanbabar8424
    @irfanbabar8424 11 หลายเดือนก่อน

    Simple & clear explanation. Thanks

  • @avichiii
    @avichiii ปีที่แล้ว

    one of the most clear explanation.

  • @zacloebs
    @zacloebs 2 ปีที่แล้ว

    First video that made me actually understand :)

  • @92501le386
    @92501le386 3 ปีที่แล้ว

    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.

  • @AdnanRizvan
    @AdnanRizvan 9 ปีที่แล้ว

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

  • @atifasadkhan
    @atifasadkhan 3 ปีที่แล้ว +1

    ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️ this was life 🧬 saver

  • @ahmedhussein6359
    @ahmedhussein6359 2 ปีที่แล้ว +4

    understanding this explanation is not a problem...the biggest problem is how someone thought that by recursing this: fib(n-1)+fib(n-2); actually gives the correct fibonacci value...that is something i cannot wrap my mind around...if you don't understand what i am trying to say, if the same fibonacci code was asked to be written in an iterative manner, i can logically come up with a solution in a jiffy...but if you ask me to give that solution using recursion, i would have no clue....of coz now i would write this code....but that's just rot memorization...i wouldn't have thought of that...

    • @EntrepreneurAffiliate
      @EntrepreneurAffiliate 2 ปีที่แล้ว

      100% look up proof of fibonacci sequence using recursion, everything is mathematically proven including all types of sorting algorithms and what not. Math is awesome!!

    • @wh.n
      @wh.n 2 ปีที่แล้ว

      As Haydar said, that's why there is a whole field for people learning to prove things. People have different time constraints. Right now, we just learned the way to break down this problem, in an 8 minutes video, 8 MINUTES. Plus if it is easy to begin with, these videos would not even exist.

    • @ryun_d3v
      @ryun_d3v ปีที่แล้ว

      So true! I'd love to understand how to arrive to this solution!

  • @PratikDeshmane7006
    @PratikDeshmane7006 5 ปีที่แล้ว +2

    Finally got the perfect explanation!

  • @Nasimkhadv1996
    @Nasimkhadv1996 ปีที่แล้ว

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

  • @felipelima2724
    @felipelima2724 5 ปีที่แล้ว +2

    Very good explanation!!! The best!

  • @DrDerivative
    @DrDerivative 3 ปีที่แล้ว

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

  • @ammgnero
    @ammgnero 4 ปีที่แล้ว

    Holy Moly
    wonderful explanation sir

  • @codaacademy5888
    @codaacademy5888 ปีที่แล้ว

    this is the best explanation , really thanks

  • @voltron909
    @voltron909 12 ปีที่แล้ว

    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.

  • @RayOnTheInternet
    @RayOnTheInternet 6 ปีที่แล้ว +1

    Finally a clear, visual representation. Thank you so much

  • @bradleonn
    @bradleonn 6 หลายเดือนก่อน

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

  • @black_squall
    @black_squall 11 ปีที่แล้ว +1

    take a sip of beer every time he says fibonacci in this video

  • @wildfyah
    @wildfyah 5 ปีที่แล้ว +3

    And just like that my headache went away. Thanks.

  • @hassan-rakib
    @hassan-rakib 3 ปีที่แล้ว +1

    Genius! Saved my day!!

  • @FredMaher
    @FredMaher ปีที่แล้ว

    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.

  • @zeeshan1019
    @zeeshan1019 ปีที่แล้ว +1

    Lovely sir

  • @min_808
    @min_808 ปีที่แล้ว

    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

  • @ronglass5968
    @ronglass5968 7 ปีที่แล้ว +2

    Beautifully explained. Thank you!

  • @markkillion6845
    @markkillion6845 2 ปีที่แล้ว

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

  • @ansekao4516
    @ansekao4516 3 ปีที่แล้ว

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

  • @SosetaFurioasaJr
    @SosetaFurioasaJr 3 ปีที่แล้ว +1

    Drinking game - take 1 shot every time he says fibonacci.

  • @himanshusaxena8639
    @himanshusaxena8639 2 ปีที่แล้ว

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

  • @martinmoragab
    @martinmoragab 3 ปีที่แล้ว

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

  • @thatssodinesh7857
    @thatssodinesh7857 9 หลายเดือนก่อน

    OMG! thank you!! I finally understood this!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @nikosspiropoulos8417
    @nikosspiropoulos8417 2 ปีที่แล้ว

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

  • @phantom_drone
    @phantom_drone 4 ปีที่แล้ว

    Everything makes sense now, much thanks

  • @abdallahelnashar1520
    @abdallahelnashar1520 2 ปีที่แล้ว

    Wooooow Thank you very much Greatest Explanation Ever!!!

  • @rbianchidev
    @rbianchidev 6 ปีที่แล้ว +2

    it's the clearest explanation I've found on internet 😉

  • @cellmaker1
    @cellmaker1 2 ปีที่แล้ว

    This is extremely helpful. Thanks

  • @zoverlvx8094
    @zoverlvx8094 6 ปีที่แล้ว +1

    When an explanation's so good that you need a cigarette. I don't even smoke!

  • @andregomes7232
    @andregomes7232 2 ปีที่แล้ว

    Thank you so much man! you made it looks easy

  • @christanprice5720
    @christanprice5720 2 ปีที่แล้ว

    This was extremely helpful!

  • @hansnery
    @hansnery 4 ปีที่แล้ว

    Thank you, I finally understood how it works now.

  • @lestra378
    @lestra378 2 ปีที่แล้ว

    Thank you for this amazing explanation

  • @baryosef6245
    @baryosef6245 7 ปีที่แล้ว

    Amazing explanation. You are awesome!

  • @danielarista1352
    @danielarista1352 ปีที่แล้ว +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).

  • @cedricmendoza8316
    @cedricmendoza8316 3 ปีที่แล้ว

    Always quality content. Thank you.

  • @yadatis5905
    @yadatis5905 6 ปีที่แล้ว +1

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

  • @vishnu364
    @vishnu364 3 ปีที่แล้ว

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

  • @crakintosh
    @crakintosh 13 ปีที่แล้ว +1

    Thnk u sal for starting cs tuts.. But i hav one question,how does the computer understand english language

  • @ars7070
    @ars7070 6 ปีที่แล้ว

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