-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40b3de3
commit e3bbfd8
Showing
51 changed files
with
3,927 additions
and
3,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,89 @@ | ||
### Exercises 4.2-1 | ||
*** | ||
Use a recursion tree to determine a good asymptotic upper bound on the recurrence | ||
### Exercises 4.2-1 | ||
*** | ||
Use a recursion tree to determine a good asymptotic upper bound on the recurrence | ||
 = 3T\(\\lceil n/2 \\rceil\) + n). Use the substitution method to verify your answer. | ||
|
||
### `Answer` | ||
 | ||
|
||
树的高度是lgn,有3^lgn个叶子节点. | ||
|
||
 = n\\sum_{i = 0}^{lg\(n\)-1}\(\\frac{3}{2}\)^i + \\Theta\(3^{\\lg{n}}\) \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(3^{\\lg{n}}\) \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(n^{\\lg{3}}\) \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) | ||
) | ||
|
||
我们猜想  \\le cn^{\\lg{3}}+2n ) | ||
|
||
 \\le 3c\(n/2\)^{\\lg{3}} + 2n \\\\ ~ | ||
\\hspace{15 mm} \\le cn^{\\lg{3}}+2n \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) | ||
) | ||
|
||
|
||
### Exercises 4.2-2 | ||
*** | ||
Argue that the solution to the recurrence | ||
 = T\(n/3\) + T\(2n/3\) + cn ) | ||
, where c is a constant, is Ω(nlgn) by appealing to the recurrsion tree. | ||
|
||
### `Answer` | ||
最短的叶子高度是lg3n,每一层都要cn.也就是说,只考虑最短叶子的那一层(忽略其他层)已经有cnlg3n. | ||
|
||
|
||
### Exercises 4.2-3 | ||
*** | ||
Draw the recursion tree for | ||
 = 4T\(\\lfloor n/2 \\rfloor\) + cn) | ||
,where c is a constant, and provide a tight asymptotic bound on its solution. Verify your bound by the substitution method. | ||
### `Answer` | ||
 | ||
|
||
很明显是n^2的级别 | ||
|
||
我们假设  \\le n^2+2cn) | ||
|
||
 \\le 4c\(n/2\)^2 + 2cn/2+cn \\le cn^2+2cn) | ||
|
||
我们假设  \\ge n^2+2cn) | ||
|
||
 \\ge 4c\(n/2\)^2 + 2cn/2+cn \\ge cn^2+2cn) | ||
|
||
### Exercises 4.2-4 | ||
*** | ||
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) = T(n - a) + T(a) + cn, where a ≥ 1 and c > 0 are constants. | ||
|
||
### `Answer` | ||
 | ||
file:///Users/ganzhenchao/Workspaces/CLRS/C04-Recurrences/repo/s2/4.png | ||
 = \\sum_{i=0}^{n/a}c\(n-ia\) + \(n/a\)ca | ||
= \\Theta\(n^2\)) | ||
|
||
我们假设  \\le cn^2) | ||
|
||
 \\le c\(n-a\)^2 + ca + cn \\\\ ~ | ||
\\hspace{15 mm} \\le cn^2-2acn+ca+cn \\\\ ~ | ||
\\hspace{15 mm} \\le cn^2-c\(2an-a-n\) \\\\ ~ | ||
\\hspace{15 mm}\\le cn^2 - cn ~~~~ if ~~ a > 1/2,n > 2a \\\\ ~ | ||
\\hspace{15 mm}\\le cn^2 \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^2\) | ||
) | ||
|
||
另外一个方向的证明和这个基本一样. | ||
|
||
### Exercises 4.2-5 | ||
*** | ||
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) = T(αn) +T((1 - α)n) + cn, where α is a constant in the range 0 <α < 1 and c > 0 is also a constant. | ||
|
||
### `Answer` | ||
 | ||
|
||
可以假设α < 1/2,因此树的高度有 | ||
|
||
 = \\sum_{i = 0}^{\\log_{1/ \\alpha}{n}}cn + \\Theta\(n\) = cn\\log_{1/ \\alpha}{n} + \\Theta\(n\) = \\Theta\(n\\lg{n}\) ) | ||
|
||
*** | ||
Follow [@louis1992](https://github.com/gzc) on github to help finish this task. | ||
|
||
### `Answer` | ||
 | ||
|
||
树的高度是lgn,有3^lgn个叶子节点. | ||
|
||
 = n\\sum_{i = 0}^{lg\(n\)-1}\(\\frac{3}{2}\)^i + \\Theta\(3^{\\lg{n}}\) \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(3^{\\lg{n}}\) \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(n^{\\lg{3}}\) \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) | ||
) | ||
|
||
我们猜想  \\le cn^{\\lg{3}}+2n ) | ||
|
||
 \\le 3c\(n/2\)^{\\lg{3}} + 2n \\\\ ~ | ||
\\hspace{15 mm} \\le cn^{\\lg{3}}+2n \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) | ||
) | ||
|
||
|
||
### Exercises 4.2-2 | ||
*** | ||
Argue that the solution to the recurrence | ||
 = T\(n/3\) + T\(2n/3\) + cn ) | ||
, where c is a constant, is Ω(nlgn) by appealing to the recurrsion tree. | ||
|
||
### `Answer` | ||
最短的叶子高度是lg3n,每一层都要cn.也就是说,只考虑最短叶子的那一层(忽略其他层)已经有cnlg3n. | ||
|
||
|
||
### Exercises 4.2-3 | ||
*** | ||
Draw the recursion tree for | ||
 = 4T\(\\lfloor n/2 \\rfloor\) + cn) | ||
,where c is a constant, and provide a tight asymptotic bound on its solution. Verify your bound by the substitution method. | ||
### `Answer` | ||
 | ||
|
||
很明显是n^2的级别 | ||
|
||
我们假设  \\le n^2+2cn) | ||
|
||
 \\le 4c\(n/2\)^2 + 2cn/2+cn \\le cn^2+2cn) | ||
|
||
我们假设  \\ge n^2+2cn) | ||
|
||
 \\ge 4c\(n/2\)^2 + 2cn/2+cn \\ge cn^2+2cn) | ||
|
||
### Exercises 4.2-4 | ||
*** | ||
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) = T(n - a) + T(a) + cn, where a ≥ 1 and c > 0 are constants. | ||
|
||
### `Answer` | ||
 | ||
file:///Users/ganzhenchao/Workspaces/CLRS/C04-Recurrences/repo/s2/4.png | ||
 = \\sum_{i=0}^{n/a}c\(n-ia\) + \(n/a\)ca | ||
= \\Theta\(n^2\)) | ||
|
||
我们假设  \\le cn^2) | ||
|
||
 \\le c\(n-a\)^2 + ca + cn \\\\ ~ | ||
\\hspace{15 mm} \\le cn^2-2acn+ca+cn \\\\ ~ | ||
\\hspace{15 mm} \\le cn^2-c\(2an-a-n\) \\\\ ~ | ||
\\hspace{15 mm}\\le cn^2 - cn ~~~~ if ~~ a > 1/2,n > 2a \\\\ ~ | ||
\\hspace{15 mm}\\le cn^2 \\\\ ~ | ||
\\hspace{15 mm} = \\Theta\(n^2\) | ||
) | ||
|
||
另外一个方向的证明和这个基本一样. | ||
|
||
### Exercises 4.2-5 | ||
*** | ||
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) = T(αn) + | ||
T((1 - α)n) + cn, where α is a constant in the range 0 <α < 1 and c > 0 is also a constant. | ||
|
||
### `Answer` | ||
 | ||
|
||
可以假设α < 1/2,因此树的高度有 | ||
|
||
 = \\sum_{i = 0}^{\\log_{1/ \\alpha}{n}}cn + \\Theta\(n\) = cn\\log_{1/ \\alpha}{n} + \\Theta\(n\) = \\Theta\(n\\lg{n}\) ) | ||
|
||
*** | ||
Follow [@louis1992](https://github.com/gzc) on github to help finish this task. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,80 @@ | ||
### Exercises 4.3-1 | ||
*** | ||
Use the master method to give tight asymptotic bounds for the following recurrences. | ||
|
||
a.  = 4T\(n/2\)+n ) | ||
|
||
b.  = 4T\(n/2\)+n^2 ) | ||
|
||
### Exercises 4.3-1 | ||
*** | ||
Use the master method to give tight asymptotic bounds for the following recurrences. | ||
|
||
a.  = 4T\(n/2\)+n ) | ||
|
||
b.  = 4T\(n/2\)+n^2 ) | ||
|
||
c.  = 4T\(n/2\)+n^3 ) | ||
|
||
### `Answer` | ||
 | ||
|
||
a.  ) | ||
|
||
b.  ) | ||
|
||
c.  ) | ||
|
||
|
||
### Exercises 4.3-2 | ||
*** | ||
The recurrence T(n) = 7T (n/2)+n2 describes the running time of an algorithm A. A competing algorithm A′ has a running time of T′(n) = aT′(n/4) + n2. What is the largest integer value for a such that A′ is asymptotically faster than A? | ||
|
||
### `Answer` | ||
根据主定理,算法A的运行时间为 = \\Theta\(\\lg{7}\)\ \\approx n^{2.8} ) | ||
|
||
A'的运行时间在a > 16时超过n^2,此时 | ||
|
||
 = \\Theta\(n^{\\log_{4}{a}}\) < \\lg{7} = \\log_{4}{49}) | ||
|
||
所以最大值为48 | ||
|
||
|
||
|
||
### Exercises 4.3-3 | ||
*** | ||
Use the master method to show that the solution to the binary-search recurrence T(n) = T (n/2)+ Θ(1) is T(n) = Θ(lg n). (See Exercise 2.3-5 for a description of binary search.) | ||
### `Answer` | ||
 | ||
|
||
so the solution is Θ(lgn). | ||
|
||
|
||
### Exercises 4.3-4 | ||
*** | ||
Can the master method be applied to the recurrence | ||
 = 4T\(n/2\) + n^2 \\lg{n} ) | ||
### `Answer` | ||
 | ||
|
||
a.  ) | ||
|
||
b.  ) | ||
|
||
c.  ) | ||
|
||
|
||
### Exercises 4.3-2 | ||
*** | ||
The recurrence T(n) = 7T (n/2)+n2 describes the running time of an algorithm A. A competing algorithm A′ has a running time of T′(n) = aT′(n/4) + n2. What is the largest integer value for a such that A′ is asymptotically faster than A? | ||
|
||
### `Answer` | ||
根据主定理,算法A的运行时间为 = \\Theta\(\\lg{7}\)\ \\approx n^{2.8} ) | ||
|
||
A'的运行时间在a > 16时超过n^2,此时 | ||
|
||
 = \\Theta\(n^{\\log_{4}{a}}\) < \\lg{7} = \\log_{4}{49}) | ||
|
||
所以最大值为48 | ||
|
||
|
||
|
||
### Exercises 4.3-3 | ||
*** | ||
Use the master method to show that the solution to the binary-search recurrence T(n) = T (n/2) | ||
+ Θ(1) is T(n) = Θ(lg n). (See Exercise 2.3-5 for a description of binary search.) | ||
### `Answer` | ||
 | ||
|
||
so the solution is Θ(lgn). | ||
|
||
|
||
### Exercises 4.3-4 | ||
*** | ||
Can the master method be applied to the recurrence | ||
 = 4T\(n/2\) + n^2 \\lg{n} ) | ||
Why or why not? Give an asymptotic upper bound for this recurrence. | ||
|
||
### `Answer` | ||
 | ||
|
||
The problem is that it is not polynomially larger. The ratio  | ||
 / n^{\\log_{b}{a}} = \\lg{n}) | ||
is asymptotically less than | ||
 for any positive constant | ||
 | ||
|
||
### Exercises 4.3-5 | ||
*** | ||
Consider the regularity condition af (n/b) ≤ cf(n) for some constant c < 1, which is part of case 3 of the master theorem. Give an example of constants a ≥ 1 and b > 1 and a function f (n) that satisfies all the conditions in case 3 of the master theorem except the regularity condition. | ||
|
||
### `Answer` | ||
let | ||
|
||
a = 1 | ||
b = 2 | ||
f(n) = 2 - cos(n) | ||
|
||
我们需要证明 | ||
|
||
}\) < cn \\\\ ~ \\Rightarrow c > \\frac{2- \\cos\(n/2\)}{2} \\\\ ~ | ||
\\Rightarrow c > \\frac{3}{2} | ||
) | ||
|
||
*** | ||
Follow [@louis1992](https://github.com/gzc) on github to help finish this task. | ||
|
||
|
||
### `Answer` | ||
 | ||
|
||
The problem is that it is not polynomially larger. The ratio  | ||
 / n^{\\log_{b}{a}} = \\lg{n}) | ||
is asymptotically less than | ||
 for any positive constant | ||
 | ||
|
||
### Exercises 4.3-5 | ||
*** | ||
Consider the regularity condition af (n/b) ≤ cf(n) for some constant c < 1, which is part of case 3 of the master theorem. Give an example of constants a ≥ 1 and b > 1 and a function f (n) that satisfies all the conditions in case 3 of the master theorem except the regularity condition. | ||
|
||
### `Answer` | ||
let | ||
|
||
a = 1 | ||
b = 2 | ||
f(n) = 2 - cos(n) | ||
|
||
我们需要证明 | ||
|
||
}\) < cn \\\\ ~ \\Rightarrow c > \\frac{2- \\cos\(n/2\)}{2} \\\\ ~ | ||
\\Rightarrow c > \\frac{3}{2} | ||
) | ||
|
||
*** | ||
Follow [@louis1992](https://github.com/gzc) on github to help finish this task. | ||
|
Oops, something went wrong.