What are some of the differences between using recursion to solve a problem versus using iteration?
来源:互联网 发布:pkpm建筑设计软件 编辑:程序博客网 时间:2024/06/05 04:28
The fact is that recursion is rarely the most efficient approach to solving a problem, and iteration is almost always more efficient. This is because there is usually more overhead associated with making recursive calls due to the fact that the call stack is so heavily used during recursion (for a refresher on this, read here: Recursion tutorial). This means that many computer programming languages will spend more time maintaining the call stack then they will actually performing the necessary calculations.
Does recursion use more memory than iteration?
Generally speaking, yes it does. This is because of the extensive use of the call stack.
Should I use recursion or iteration?
Recursion is generally used because of the fact that it is simpler to implement, and it is usually more ‘elegant’ than iterative solutions. Remember that anything that’s done in recursion can also be done iteratively, but with recursion there is generally a performance drawback. But, depending on the problem that you are trying to solve, that performance drawback can be very insignificant – in which case it makes sense to use recursion. With recursion, you also get the added benefit that other programmers can more easily understand your code – which is always a good thing to have.
- What are some of the differences between using recursion to solve a problem versus using iteration?
- What are the differences between a pointer variable and a reference variable in C++?
- What are the differences between HDMI versions 1.1, 1.2, 1.3a, 1.4a and 2.0?
- What are the differences between a pointer variable and a reference variable in C++?
- What Are the Differences Between Smaller Couriers and FedEx-_899
- What are the differences between LDAP and Active Directory?
- What are the differences between nil, NULL and [NSNULL nil]?
- What are the Differences between Work Package and Planning Package?
- What are the differences between struct and class in C++?
- What are the differences between numpy arrays and matrices
- What are the differences between Apache Kafka and RabbitMQ?
- [Python]--What are the differences between numpy arrays and matrices?
- recursion versus iteration
- The differences between some patterns.
- Write a program to print the fibonacci series sum upto a particular no. using recursion.
- What are the problems that a NoSQL database tries to solve?
- the "true story" about using data mining to identify a relation between sales of beer and diapers
- What is the difference between using a script and an animation?
- Android 对话框(Dialog)【大全】
- android分析windowManager、window、viewGroup之间关系
- 建造者模式
- 从今天开始
- bzoj3669 魔法森林(NOI 2014)
- What are some of the differences between using recursion to solve a problem versus using iteration?
- java volatile double、long的原子性
- 平均一个集合为几个集合
- #DOM操作
- php历史版本页面
- 在C#应用中使用Matlab函数
- tar加减号时的作用 tar cf - | tar xf - 管道 linux
- Android 开发 调用图库选择图片实现和参数详解
- Restful Web Services