递归的优点和缺点是什么? [英] What are the advantages and disadvantages of recursion?

查看:58
本文介绍了递归的优点和缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于在排序算法中使用递归而不是非递归方法,或者就此而言,任何算法的优缺点是什么?

With respect to using recursion over non-recursive methods in sorting algorithms or, for that matter, any algorithm what are its pros and cons?

推荐答案

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

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:

链接

这篇关于递归的优点和缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆