Cracking the code interview总结
来源:互联网 发布:金马网络服装批发城 编辑:程序博客网 时间:2024/05/22 12:48
1. 第八章:递归
程序调用自己称为递归。把大问题化成与自身相类似的小问题。递归需要边界条件,递归前进段,递归返回段。当边界条件不满足时,递归前进,当边界条件满足时,递归返回。空间成本&时间成本相对较大。
(1)动态规划:
节约时间&空间,把重复性的计算记录下来。如斐波拉契数列,采用递归的算法复杂度为O(n^2),动态规划为O(n).
if(n<=1) return ;frist = last =1;for(i=2,i<=n,i++){ answer = frist + last; frist = last; last = answer;}return answer;
补充:卡塔兰数
(1) h(n)=h(0)*h(n-1)+h(1)*h(n-2)+…+h(n-1)*h(0). 这是一个递归的公式。
(2) h(n)=c(n2,n)/(n+1). 由这个公式可以直接求出h(n),不需要知道h(n-1)…h(0).
在直接想要知道h(n)的时候,公式(2)很好用,但是在解决一些算法问题的时候,第一个公式更有用些,因为这一类算法全都能搞成公式(1)的样子求解。
0 0
- Cracking the code interview总结
- cracking the code interview problem 1.1
- cracking the code interview problem 1.3
- cracking the code interview balanced tree python
- cracking the code interview LCA Python
- cracking code interview
- Cracking the code interview 面试题:两个数相加
- Cracking the Code Interview (1): 跟踪数组的中位数
- Replace all spaces in string with ' ' (Cracking the Code Interview)
- 笔记摘录——Cracking the code interview
- cracking the code interview convert array to BST Python
- Cracking the Code Interview Chapter One-- TaylorZhangYuxin's Solusion
- Cracking the Code Interview Chapter Two-- TaylorZhangYuxin's Solusion
- cracking the code interview——c++实现
- Cracking the Code Interview Chapter Three-- TaylorZhangYuxin's Solusion
- Cracking the Coding Interview
- 《Cracking the coding interview》
- Cracking The Coding Interview
- ThinkPHP 3.1.2 视图-1
- Objective - C CALayer的简介
- CDHtmlDialog的基本使用
- Git 换行符自动转换
- C语言基础函数 判断是否闰年
- Cracking the code interview总结
- VC屏幕截图并保存为bmp、jpg、png等格式文件
- IOS-UI学习笔记(超级猜图)
- 函数-从进程名获得进程ID、从进程ID获得进程路径
- 卷积神经网络源码——最终输出部分的理解
- Hive外部分区表加载flume打到hdfs上文件,读不到.tmp文件
- JVM1
- waitpid函数使用
- 文件的自定义包发送接收