跳转至

4.13. 总结

4.13. Summary

在本章中,我们讨论了几个递归算法的例子。这些算法的选择是为了让你接触到一些递归作为有效问题解决技术的不同问题。需要记住的关键点如下:

  • 所有递归算法必须有一个基本情况。
  • 递归算法必须改变其状态并向基本情况迈进。
  • 递归算法必须调用自身(递归地)。
  • 在某些情况下,递归可以代替迭代。
  • 递归算法往往非常自然地映射到你试图解决的问题的正式表达式上。
  • 递归并不总是答案。有时,递归解决方案可能比其他算法更耗费计算资源。

In this chapter we have looked at examples of several recursive algorithms. These algorithms were chosen to expose you to several different problems where recursion is an effective problem-solving technique. The key points to remember from this chapter are as follows:

  • All recursive algorithms must have a base case.
  • A recursive algorithm must change its state and make progress toward the base case.
  • A recursive algorithm must call itself (recursively).
  • Recursion can take the place of iteration in some cases.
  • Recursive algorithms often map very naturally to a formal expression of the problem you are trying to solve.
  • Recursion is not always the answer. Sometimes a recursive solution may be more computationally expensive than an alternative algorithm.

最后更新: 2024年9月12日
创建日期: 2024年9月9日