danger of recursive functions

前端 未结 4 1373
清酒与你
清酒与你 2021-01-05 05:03

Often people say that it\'s not recommended to use recursive functions in python (recursion depth restrictions, memory consumption, etc)

I took a permutation example

4条回答
  •  孤城傲影
    2021-01-05 05:26

    Recursion is good for problems that lend themselves to clean, clear, recursive implementations. But like all programming you must perform some algorithm analysis to understand the performance characteristics. In the case of recursion, besides number of operations you must also estimate the maximum stack depth.

    Most problems occur when new programmers assume recursion is magical and don't realize there is a stack underneath making it possible. New programmers have also been known to allocate memory and never free it, and other mistakes, so recursion is not unique in this danger.

提交回复
热议问题