4.13. 总结
.. Copyright (C) Brad Miller, David Ranum This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
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.
创建日期: 2023年10月10日