Recursion and Iteration

前端 未结 7 568
故里飘歌
故里飘歌 2020-12-18 08:43

What is the difference? Are these the same? If not, can someone please give me an example?

MW: Iteration - 1 : the action or a process of iterating or repeating: as

7条回答
  •  情书的邮戳
    2020-12-18 09:21

    [Hurry and trump this!]

    One form can be converted to the other, with one notable restriction: many "popular" languages (C/Java/normal Python) do not support TCO/TCE (tail-call-optimization/tail-call-elimination) and thus using recursion will 'add extra data to the stack' each time a method calls itself recursively.

    So in C and Java, iteration is idiomatic, whereas in Scheme or Haskell, recursion is idiomatic.

提交回复
热议问题