What is a practical difference between a loop and recursion

前端 未结 9 2565
无人共我
无人共我 2021-02-19 22:42

I am currently working in PHP, so this example will be in PHP, but the question applies to multiple languages.

I am working on this project with a fiend of mine, and as

9条回答
  •  名媛妹妹
    2021-02-19 23:03

    In general, a recursive function will consume more stack space (since it's really a large set of function calls), while an iterative solution won't. This also means that an iterative solution, in general, will be faster because.

    I am not sure if this applies to an interpreted language like PHP though, it is possible that the interpreter can handle this better.

提交回复
热议问题