Advantage and Disadvantage of Recursion

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

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

  • @s.o.s6201
    @s.o.s6201 3 ปีที่แล้ว +25

    100% no-nonsense content...
    keep up the great work sir... we count on u.

  • @daverussell4052
    @daverussell4052 3 ปีที่แล้ว +14

    I like the way you say "let me tell you my dear friend" lol...

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

      @Koda Jax wtf

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

      @Koda Jax its only getting the information and not the real password.. and the password covered with stars is not the same with the real password.. i know it because i tried to hack myself but the length of the stars is different with my password

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

      @Avery Johnny buzzeerrr

  • @AnilKumarReddySadhu-r5z
    @AnilKumarReddySadhu-r5z หลายเดือนก่อน

    Great job sir. You are making things simpler for us and love you

  • @brocklesnarufcchamp1
    @brocklesnarufcchamp1 4 ปีที่แล้ว +30

    Recursive Program
    Advantage: Elegant
    Disadvantage: Complex
    Iterative Program
    Advantage: Simple
    Disadvantage: Lengthy

    • @sweatyhands9830
      @sweatyhands9830 3 ปีที่แล้ว +4

      Lengthy and ugly, you guys better become average recursion enjoyers, not average loops fans

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

      instablaster...

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

      @@sweatyhands9830
      Lengthy and ugly in what kind of case?

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

      @@lucascabrellibr in every case. i don't like loops

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

      @@sweatyhands9830 but it's hard

  • @r.padmapriya1562
    @r.padmapriya1562 ปีที่แล้ว

    Easily Understood. Explanation Superb Sir.

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

    Super explanation sir your videos are amazing

  • @timirchatterjee2636
    @timirchatterjee2636 4 ปีที่แล้ว +8

    Your lectures r fantastic... Very much helpful

  • @jayedhossainbreb-pbs9849
    @jayedhossainbreb-pbs9849 4 ปีที่แล้ว +1

    Awesome explanation.

  • @HomakHakerok
    @HomakHakerok 6 ปีที่แล้ว +16

    And what about the cost of the algorithm?
    As far as I know, some algorithms require fewer calculations in a recursive way. Maybe you can do it as cheap as recursive ones in iterative but I think the code will be really hard to understand.

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

    You are the best teacher, I mean it!

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

    Sir, can u tell me the practical example where loop is better than recursion and viceversa

  • @mohdfaisal2472
    @mohdfaisal2472 5 ปีที่แล้ว +8

    I am very thankful to neso academy which helped me in clearing subjects like automata theory and digital logic.....sir can u inform when r u going to start lectures on python programming...

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

    Grate sir keep it up

  • @GergiH
    @GergiH 4 ปีที่แล้ว +14

    Recursive functions are more "elegant" (what that word even means in programming... rather sounds like an ego thing) and easy to understand?
    I strongly disagree. Any level of programmer would understand most loops/iterations at a glance, but a recursive function which is not only these dummy examples with 4 lines of code, I think most would be lost at first (include me).

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

    Nice explanation

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

    You can't implement Ackermann's recursive function with iteration..

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

    @Neso Academy, is it also the case that the recursive approach is faster in time in comparison to iterative for real world coding implementation?

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

      Not in the example he gave, recursion provides a performance benefit when your problem can apply a divide and conquer approach to solving it. The factorial calculation just provides a good way to visualize the way recursion works. Any problem that needs to search a tree structure tends to be a good example of where you can use recursion efficiently.

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

    Thanks for helping us sir

  • @pratyushharsh7186
    @pratyushharsh7186 5 ปีที่แล้ว +8

    Correction at 1:14,
    Every recursive code cannot be written iteratively like the Ackermann function

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

      yes it can.the first link explains it.the 2nd and third ara 2 codes of Ackermann function without recursion(iteratively)
      www.quora.com/Why-cant-Ackermann-function-be-calculated-iteratively
      gist.github.com/Sebbyastian/9bf5551f915b2694c77e
      codereview.stackexchange.com/questions/156552/iterative-implementation-of-the-ackermann-function

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

      Thanks @red_l

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

      The Ackermann function can be computed iteratively. However, the Ackermann function is not a primitive recursive function, and this fact is connected to one specific type of iterative computation.
      Intuitively, primitive recursive functions are functions that can be implemented in a simple programming language in which the only type of iteration you can use is a for-cycle with a fixed number of iterations. (I.e., when the for-cycle starts, you have to state the lower and upper bound of the iteration, and you cannot cheat by modifying the iteration variable inside the cycle.)
      The result that the Ackermann function is computable but not primitive recursive is important because it shows that the for-cycle, on its own, is not strong enough to make a programming language Turing complete. You need a stronger form of iteration, for example a while-cycle, or general recursion.

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

    Sir, every iterative problems can we write with the help of recursion?

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

    Sir can you please let us know the solution of home work problems btw best video lectures on youtube

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

    what is the actual relationship between number of lines and the memory?

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

    Great video! Do more stack frames mean more computational time? I feel like that would be true but I’m not sure

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

      No stack frame is free memory during runtime.

  • @brunomarsellio4391
    @brunomarsellio4391 5 หลายเดือนก่อน

    Does recursion take more stack memory than iteration?

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

    احلي تحيه لرجاله الهند

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

    where are the data structures part in this series?

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

    Thank you so much

  • @dr.anubhavkumarprasad5765
    @dr.anubhavkumarprasad5765 5 ปีที่แล้ว

    Please provide computational time difference if any

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

    Which path should we follow in competitive and interview based programming!??

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

    Can anyone recall me what is stack and what is the use of it?

    • @Ridick1460
      @Ridick1460 4 ปีที่แล้ว +5

      Stack helps the program know where in the code it is. When you call a function your program must know where it was before calling it, so it can return there after completing the function. Also the stack keeps registers saved in case you alter any of them during function execution, so that they can be returned to "normal" after completed

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

    Program-1: tail recursive
    Program-2: non tail recursive

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

    int fact(int n):
    if n < 0: return -1
    result = 1:
    for(int x = 1; x < n; x++):
    result *= x
    return result
    vio la! same lines of code

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

      Condition would be x

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

      @@mihirvora391 buggy isnt it haha

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

    I find it really bewildering hearing programmers using terms like: "elegant" "clean" "simple" - because these are not quantifiable, but rather a matter of personal taste or even a tradition ("all the developers say that..." "all the developers learned from other developers to like/praise/appreciate it that way ...".
    E.g. I find iteration more systematic (or even linear) approach and therefore easier to comprehend (what is being done when) then recursion, that forces ones mind to wrap itself around non-linear thinking (something calling itself calling itself ...). Despite developers pointing fingers at recursion and saying it looks cleaner/simpler - when it actually does not. :)
    I yet have to find explanations that sound technical. I'd be more interested in number of operations, memory use, speed etc.

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

    Which path is fast?

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

    Difference between Recursion vs callback function pls tell

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

    So, what I got from that was... always do iterative. Who cares about 'elegance'? If iterative uses less memory and executes faster, then it's just better. But I'm a total newbie, so maybe I'm totally misconstruing something here?

    • @tyrannosauce
      @tyrannosauce 8 หลายเดือนก่อน

      It is actually not that way. Elegance and less lines of code enhance readability and understanding of programs, which can be ignored in simpler programs but is of paramount importance in long and complex programs.

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

    What about the performance?

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

    sir, what about the time complexity which one is better?

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

    Actually, I think the number of lines of code is also defines the space. Here, recursion has less number of lines but it occupies more stack space than iteration, then please let me know that what is the actual relationship between number of lines and the memory?

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

    Thank u

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

    advantage of recursion you just have freaking less line like 1 or 2 lines and it's look more complex that make you think yourself looks cool
    at the cost of using stack and sometimes transverse tree.
    best loop vs best recursion of a program always perform better the loops that is
    and guess what sometimes recursion only get better when the compiler change it's to loop using what's called "tail call optimization"
    the only to write it if you're in a hurry and you also used to recursion else it's suck for other programmer

  • @b.himanshu2654
    @b.himanshu2654 4 ปีที่แล้ว

    Nice

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

    Which path takes less time!

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

      Iteration is always faster than recursion except in the case that the method call goes straight the recursive methods base case

  • @CG-vd4nu
    @CG-vd4nu 2 ปีที่แล้ว

    Except we know that recursion is not more elegant and actually requires more memory than iterative.

  • @akashranjan878
    @akashranjan878 8 หลายเดือนก่อน

    Sorry to say Advantage and Disadvantage of Recursion was not mentioned properly here.

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

    🖤🖤

  • @zoreladreanrivera9822
    @zoreladreanrivera9822 8 หลายเดือนก่อน

    but for me, iterative is easier to understand

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

    Sir please hindi me bole 😢😢😢

  • @جيمرمصري-ق5ق
    @جيمرمصري-ق5ق 5 ปีที่แล้ว

    but doesnt more lines mean more space

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

      More space in RAM. Also can be bigger compiled.

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

      Space will be occupied when you store something
      In recursion we store value at every function call