Files
Learn-Algorithms/8 Algorithms Analysis/递归.md
T
2021-03-18 21:24:06 +08:00

38 lines
812 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 递归
递归是一种设计和描述算法的有力工具。 递归算法执行过程分 `递推` 和 `回归` 两个阶段
在 `递推` 阶段,将大的问题分解成小的问题
在 `回归` 阶段,获得最简单问题的解后,逐级返回,依次得到稍微复杂情况的解,知道获得最终的结果
1) 确定递归公式
2) 确定边界条件
#### 斐波那契数列
fib(n)=fib(n-1)+fib(n-2)
递归实现
```
```
非递归实现
```
```
#### 其它案例
阶乘计算
梵塔问题 (三根针1,2,3表示,1号从小到大n个盘子,先要都移到3号上,不能出现大盘压小盘,找出移动次数最少的方案)
快速排序
递归运行效率较低,因为有函数调用的开销,递归多次也可能造成栈溢出。