[c][explained] Recursion & Fibonacci Numbers

Поделиться
HTML-код
  • Опубликовано: 4 фев 2025

Комментарии • 26

  • @awabkhan2977
    @awabkhan2977 11 месяцев назад +1

    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.

  • @asafcohen3562
    @asafcohen3562 4 года назад +15

    This is honestly an underrated RUclips channel I also love how everything is in c

    • @nextswe504
      @nextswe504 4 года назад

      it's not underrated... it has not been rated yet. :) keep up the good work @theteachr

  • @godza4735
    @godza4735 Год назад +1

    Thank you a lot , the other youtubers didn't explain as well as you for me

  • @VictorCastillo-v9p
    @VictorCastillo-v9p 6 месяцев назад

    Fantastic explanation, the graphics and animations really help

  • @mk17173n
    @mk17173n 2 года назад

    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.

  • @yuhuili6738
    @yuhuili6738 Год назад +1

    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)

    • @theteachr
      @theteachr  Год назад +1

      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?

  • @paulaneesh7
    @paulaneesh7 2 года назад +1

    Damn this video satisfied my soul

  • @yuribuzynnik1312
    @yuribuzynnik1312 5 месяцев назад

    Thank you for explanation!

  • @N3vermake
    @N3vermake 3 года назад

    I wish our professor could have explained this in 4:57 mins. Thank you so much!

  • @reiito8727
    @reiito8727 3 года назад +1

    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.

    • @theteachr
      @theteachr  3 года назад

      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.

    • @reiito8727
      @reiito8727 3 года назад

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

  • @Carrot_Jade
    @Carrot_Jade 2 года назад

    Underrated channel

  • @M.Hassan.
    @M.Hassan. 4 года назад +2

    What software did you use to make the animations?

  • @matancohen890
    @matancohen890 2 года назад

    Incredible explanation my friend

  • @viktornikolov1570
    @viktornikolov1570 3 года назад

    Helped me a lot. Thank you.

  • @fazlechistyhimel3958
    @fazlechistyhimel3958 2 года назад

    wow. amazing. explained so easily.

  • @Nonowayy
    @Nonowayy 3 года назад

    Thank you very much !!! :)

  • @abd1428
    @abd1428 3 года назад +1

    you are the best

  • @AnkeshKumar-yv8hm
    @AnkeshKumar-yv8hm 2 года назад

    Why fib2 inside fib4 return 1 it should return 0

    • @theteachr
      @theteachr  2 года назад +1

      Irrespective of from where it’s called, fib(2) will always return 1. Why do you think it should return a zero?

    • @AnkeshKumar-yv8hm
      @AnkeshKumar-yv8hm 2 года назад

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

    • @AnkeshKumar-yv8hm
      @AnkeshKumar-yv8hm 2 года назад

      Request you to reply