且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

递归的优点和缺点是什么?

更新时间:2022-06-04 08:48:55

在大多数情况下,递归更慢,并且占用更多的堆栈.递归的主要优点是对于树遍历等问题,它使算法更容易或更优雅".查看一些比较:

For the most part recursion is slower, and takes up more of the stack as well. The main advantage of recursion is that for problems like tree traversal it make the algorithm a little easier or more "elegant". Check out some of the comparisons:

链接