type
status
date
slug
summary
tags
category
icon
password
Property
Jul 13, 2023 01:59 PM
Recursion 递归
Video
Review




example :打印素数的函数
Recursion



递归对于解决具有自然重复结构的问题很有用,它们是根据自身定义的

比如:DNS 查询

这也是某种意义上的递归,直到 获取函数的结果
Recursive Function
递归函数



逐渐的将问题缩小,直到缩到最小,缩小到最小,很容得出结果,这样问题就解决了。


重在抽象,找到重复的部分

函数抽象:不要担心阶乘是递归的,只要假设阶乘得到正确的答案
Visualizing Recursion


先递到最后一层,再逐渐的归回去





How To Trust Functional Abstraction

基准的验证,并且,更大规模的计算是基于基础验证的

Identifying Patterns

这个例子中,递归并不是一个hof,因为返回的不是函数,而是函数的调用结果
Example




这种形式也是可以的,base case不是那么的具体,明显
Sum Digits



可以利用整除和区域来做


Summary

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