type
status
date
slug
summary
tags
category
icon
password
Property
Jul 13, 2023 01:59 PM
Recursion Example

Recursion (Review)


迭代和递归
迭代是依次循环,直到(不)满足条件,或者说是达到临界条件
递归是一种自上而下的思维方式,bottom-up approach

Sum Digits


Order of RecurSion Calls




需要执行到if n<10 满足之后,再结束一个函数的调用,再“归”回去执行后面的那个print函数

Two Implementations 两种实现

总结
- 两种实现一样清晰,通常简洁的更好
- 在这种情况下,更长的实现会更清晰
- 再学习递归的时候,首先写基本列子(base case)
Fibonacci





Fibonacci Call Tree

Broken Fibonacci

Error!

Counting Partitions





Call Tree


这种情况下,我已经有了这种分配方式,所以这种的数量是1



Code
- 作者:Kitety
- 链接:https://www.kitety.com/article/cs-61a-7
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章