add dsa/chp1/exercises.md.

This commit is contained in:
Shine wOng
2019-10-13 22:18:17 +08:00
parent 41b6637d3b
commit e781e318a9
2 changed files with 39 additions and 2 deletions

37
thu_dsa/chp1/exercises.md Normal file
View File

@@ -0,0 +1,37 @@
教材课后习题回答
==============
## Introduction.B
> 举例:随问题实例规模增大,同一算法的求解时间可能波动甚至下降
比如求解`hailstone(n)`的整个序列,或者求它的序列长度的算法。
> 在哪些方面现代电子计算机仍未达到RAM模型的要求
首先在RAM模型中寄存器的数量是不限的在现代计算机中则因为指令集的设计以及成本等问题寄存器的数量往往是有限的并且数量很少。
其次在RAM模型中所有基本操作都需要相同的时间这在现代计算机中也难以达到即不同的指令执行需要的时钟周期不同。在实际中是采用多次存储器架构来实现对有限的寄存器的扩充的在这些不同层次的存储器之间传递数据所需要的时间往往具有数量级级别的差别。
> 在`TM``RAM`等模型中衡量算法效率,为何通常只需考察运行的时间?
在渐进复杂度的意义下,任一算法的任何一次运行过程中所消耗的存储空间,都不会多于其间所执行的指令条数。这是因为,一条基本操作只能涉及常数规模的存储空间。
> 图灵机Increase中以下这条指令可否省略
```
(<, #, 1, R, >)
```
不可以。该指令是对应于原来的二进制整数只有全1的后缀却没有一个为零的前缀的情形对于这种情况应该把最前面一个'#'改写成'1',来表示递增之后的最高位。
> 设计一个图灵机,实现对正整数的减一(Decrease)功能
由于是正整数,该问题其实就等价于将一个带有全'0'后缀的'1'做Decrease操作其中全'0'后缀的长度可以等于零,'1'左侧也还可以有其他数字,但是对结果没有影响。
算法是,将全'0'的后缀反转为'1',将原来高位的'1'反转为'0',有以下三条操作:
```c
(<, 0; 1, L, <);
(<, 1; 0, R, >);
(>, #; #, R, h);//halt
```

View File

@@ -5,7 +5,7 @@ Conclusion on Master Theorem
In the analysis of algorithms, `Master Theorem` provides a simple way to compute the time complexity(using big O notation) for `divide-and-conquer` recurrences.
We all know that for `divide-and-conquer` algorithms, there are two way to analysis their time complexity, i.e. _recursion track_ and _recurrence equation_. Master Theorem is a way to compute such time complexity using both the two way: it tries to solve the _recurrence equation_ by means of _recusion track_.
We all know that for `divide-and-conquer` algorithms, there are two ways to analyze their time complexity, i.e. _recursion track_ and _recurrence equation_. Master Theorem is a way to compute such time complexity using both the two way: it tries to solve the _recurrence equation_ by means of _recusion track_.
## Introduction
@@ -71,7 +71,7 @@ $$
> Case 3: q > 1
$$
T(n) = n^d(1 + q + q^2 + ... + q^k) = n^d * \frac{1-q^{k+1}}{1-q} = O(n^d * q^k = O(a^{log_{b}^{n}})
T(n) = n^d(1 + q + q^2 + ... + q^k) = n^d * \frac{1-q^{k+1}}{1-q} = O(n^d * q^k) = O(a^{log_{b}^{n}})
$$
To further simplify this, we need to apply the following equation: