Skip to content

Commit e3bbfd8

Browse files
committed
Fix broken Markdown headings
1 parent 40b3de3 commit e3bbfd8

File tree

51 files changed

+3927
-3398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3927
-3398
lines changed

C04-Recurrences/4.2.md

+87-86
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,89 @@
1-
### Exercises 4.2-1
2-
***
3-
Use a recursion tree to determine a good asymptotic upper bound on the recurrence
1+
### Exercises 4.2-1
2+
***
3+
Use a recursion tree to determine a good asymptotic upper bound on the recurrence
44
![](http://latex.codecogs.com/gif.latex? T\(n\) = 3T\(\\lceil n/2 \\rceil\) + n). Use the substitution method to verify your answer.
55

6-
### `Answer`
7-
![recursion tree](./repo/s2/1.png)
8-
9-
树的高度是lgn,有3^lgn个叶子节点.
10-
11-
![](http://latex.codecogs.com/gif.latex? T\(n\) = n\\sum_{i = 0}^{lg\(n\)-1}\(\\frac{3}{2}\)^i + \\Theta\(3^{\\lg{n}}\) \\\\ ~
12-
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(3^{\\lg{n}}\) \\\\ ~
13-
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(n^{\\lg{3}}\) \\\\ ~
14-
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\)
15-
)
16-
17-
我们猜想 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\le cn^{\\lg{3}}+2n )
18-
19-
![](http://latex.codecogs.com/gif.latex? T\(n\) \\le 3c\(n/2\)^{\\lg{3}} + 2n \\\\ ~
20-
\\hspace{15 mm} \\le cn^{\\lg{3}}+2n \\\\ ~
21-
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\)
22-
)
23-
24-
25-
### Exercises 4.2-2
26-
***
27-
Argue that the solution to the recurrence
28-
![](http://latex.codecogs.com/gif.latex? T\(n\) = T\(n/3\) + T\(2n/3\) + cn )
29-
, where c is a constant, is Ω(nlgn) by appealing to the recurrsion tree.
30-
31-
### `Answer`
32-
最短的叶子高度是lg3n,每一层都要cn.也就是说,只考虑最短叶子的那一层(忽略其他层)已经有cnlg3n.
33-
34-
35-
### Exercises 4.2-3
36-
***
37-
Draw the recursion tree for
38-
![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(\\lfloor n/2 \\rfloor\) + cn)
39-
,where c is a constant, and provide a tight asymptotic bound on its solution. Verify your bound by the substitution method.
40-
### `Answer`
41-
![recursion tree](./repo/s2/2.png)
42-
43-
很明显是n^2的级别
44-
45-
我们假设 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\le n^2+2cn)
46-
47-
![](http://latex.codecogs.com/gif.latex? T\(n\) \\le 4c\(n/2\)^2 + 2cn/2+cn \\le cn^2+2cn)
48-
49-
我们假设 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\ge n^2+2cn)
50-
51-
![](http://latex.codecogs.com/gif.latex? T\(n\) \\ge 4c\(n/2\)^2 + 2cn/2+cn \\ge cn^2+2cn)
52-
53-
### Exercises 4.2-4
54-
***
55-
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.
56-
57-
### `Answer`
58-
![recursion tree](./repo/s2/3.png)
59-
file:///Users/ganzhenchao/Workspaces/CLRS/C04-Recurrences/repo/s2/4.png
60-
![](http://latex.codecogs.com/gif.latex? T\(n\) = \\sum_{i=0}^{n/a}c\(n-ia\) + \(n/a\)ca
61-
= \\Theta\(n^2\))
62-
63-
我们假设 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\le cn^2)
64-
65-
![](http://latex.codecogs.com/gif.latex? T\(n\) \\le c\(n-a\)^2 + ca + cn \\\\ ~
66-
\\hspace{15 mm} \\le cn^2-2acn+ca+cn \\\\ ~
67-
\\hspace{15 mm} \\le cn^2-c\(2an-a-n\) \\\\ ~
68-
\\hspace{15 mm}\\le cn^2 - cn ~~~~ if ~~ a > 1/2,n > 2a \\\\ ~
69-
\\hspace{15 mm}\\le cn^2 \\\\ ~
70-
\\hspace{15 mm} = \\Theta\(n^2\)
71-
)
72-
73-
另外一个方向的证明和这个基本一样.
74-
75-
### Exercises 4.2-5
76-
***
77-
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.
78-
79-
### `Answer`
80-
![recursion tree](./repo/s2/4.png)
81-
82-
可以假设α < 1/2,因此树的高度有![](http://latex.codecogs.com/gif.latex? \\log_{1/ \\alpha}{n} )
83-
84-
![](http://latex.codecogs.com/gif.latex? T\(n\) = \\sum_{i = 0}^{\\log_{1/ \\alpha}{n}}cn + \\Theta\(n\) = cn\\log_{1/ \\alpha}{n} + \\Theta\(n\) = \\Theta\(n\\lg{n}\) )
85-
86-
***
87-
Follow [@louis1992](https://github.com/gzc) on github to help finish this task.
88-
6+
### `Answer`
7+
![recursion tree](./repo/s2/1.png)
8+
9+
树的高度是lgn,有3^lgn个叶子节点.
10+
11+
![](http://latex.codecogs.com/gif.latex? T\(n\) = n\\sum_{i = 0}^{lg\(n\)-1}\(\\frac{3}{2}\)^i + \\Theta\(3^{\\lg{n}}\) \\\\ ~
12+
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(3^{\\lg{n}}\) \\\\ ~
13+
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\) + \\Theta\(n^{\\lg{3}}\) \\\\ ~
14+
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\)
15+
)
16+
17+
我们猜想 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\le cn^{\\lg{3}}+2n )
18+
19+
![](http://latex.codecogs.com/gif.latex? T\(n\) \\le 3c\(n/2\)^{\\lg{3}} + 2n \\\\ ~
20+
\\hspace{15 mm} \\le cn^{\\lg{3}}+2n \\\\ ~
21+
\\hspace{15 mm} = \\Theta\(n^{\\lg{3}}\)
22+
)
23+
24+
25+
### Exercises 4.2-2
26+
***
27+
Argue that the solution to the recurrence
28+
![](http://latex.codecogs.com/gif.latex? T\(n\) = T\(n/3\) + T\(2n/3\) + cn )
29+
, where c is a constant, is Ω(nlgn) by appealing to the recurrsion tree.
30+
31+
### `Answer`
32+
最短的叶子高度是lg3n,每一层都要cn.也就是说,只考虑最短叶子的那一层(忽略其他层)已经有cnlg3n.
33+
34+
35+
### Exercises 4.2-3
36+
***
37+
Draw the recursion tree for
38+
![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(\\lfloor n/2 \\rfloor\) + cn)
39+
,where c is a constant, and provide a tight asymptotic bound on its solution. Verify your bound by the substitution method.
40+
### `Answer`
41+
![recursion tree](./repo/s2/2.png)
42+
43+
很明显是n^2的级别
44+
45+
我们假设 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\le n^2+2cn)
46+
47+
![](http://latex.codecogs.com/gif.latex? T\(n\) \\le 4c\(n/2\)^2 + 2cn/2+cn \\le cn^2+2cn)
48+
49+
我们假设 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\ge n^2+2cn)
50+
51+
![](http://latex.codecogs.com/gif.latex? T\(n\) \\ge 4c\(n/2\)^2 + 2cn/2+cn \\ge cn^2+2cn)
52+
53+
### Exercises 4.2-4
54+
***
55+
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.
56+
57+
### `Answer`
58+
![recursion tree](./repo/s2/3.png)
59+
file:///Users/ganzhenchao/Workspaces/CLRS/C04-Recurrences/repo/s2/4.png
60+
![](http://latex.codecogs.com/gif.latex? T\(n\) = \\sum_{i=0}^{n/a}c\(n-ia\) + \(n/a\)ca
61+
= \\Theta\(n^2\))
62+
63+
我们假设 ![](http://latex.codecogs.com/gif.latex? T\(n\) \\le cn^2)
64+
65+
![](http://latex.codecogs.com/gif.latex? T\(n\) \\le c\(n-a\)^2 + ca + cn \\\\ ~
66+
\\hspace{15 mm} \\le cn^2-2acn+ca+cn \\\\ ~
67+
\\hspace{15 mm} \\le cn^2-c\(2an-a-n\) \\\\ ~
68+
\\hspace{15 mm}\\le cn^2 - cn ~~~~ if ~~ a > 1/2,n > 2a \\\\ ~
69+
\\hspace{15 mm}\\le cn^2 \\\\ ~
70+
\\hspace{15 mm} = \\Theta\(n^2\)
71+
)
72+
73+
另外一个方向的证明和这个基本一样.
74+
75+
### Exercises 4.2-5
76+
***
77+
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) = T(αn) +
78+
T((1 - α)n) + cn, where α is a constant in the range 0 <α < 1 and c > 0 is also a constant.
79+
80+
### `Answer`
81+
![recursion tree](./repo/s2/4.png)
82+
83+
可以假设α < 1/2,因此树的高度有![](http://latex.codecogs.com/gif.latex? \\log_{1/ \\alpha}{n} )
84+
85+
![](http://latex.codecogs.com/gif.latex? T\(n\) = \\sum_{i = 0}^{\\log_{1/ \\alpha}{n}}cn + \\Theta\(n\) = cn\\log_{1/ \\alpha}{n} + \\Theta\(n\) = \\Theta\(n\\lg{n}\) )
86+
87+
***
88+
Follow [@louis1992](https://github.com/gzc) on github to help finish this task.
89+

C04-Recurrences/4.3.md

+77-76
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,80 @@
1-
### Exercises 4.3-1
2-
***
3-
Use the master method to give tight asymptotic bounds for the following recurrences.
4-
5-
a. ![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(n/2\)+n )
6-
7-
b. ![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(n/2\)+n^2 )
8-
1+
### Exercises 4.3-1
2+
***
3+
Use the master method to give tight asymptotic bounds for the following recurrences.
4+
5+
a. ![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(n/2\)+n )
6+
7+
b. ![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(n/2\)+n^2 )
8+
99
c. ![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(n/2\)+n^3 )
1010

11-
### `Answer`
12-
![](http://latex.codecogs.com/gif.latex? n^{\\log_{b}{a}} = n^{\\log_{2}{4}} = n^2)
13-
14-
a. ![](http://latex.codecogs.com/gif.latex? \\Theta\(n^2\) )
15-
16-
b. ![](http://latex.codecogs.com/gif.latex? \\Theta\(n^2 \\lg{n}\) )
17-
18-
c. ![](http://latex.codecogs.com/gif.latex? \\Theta\(n^3\) )
19-
20-
21-
### Exercises 4.3-2
22-
***
23-
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?
24-
25-
### `Answer`
26-
根据主定理,算法A的运行时间为![](http://latex.codecogs.com/gif.latex? T\(n\) = \\Theta\(\\lg{7}\)\ \\approx n^{2.8} )
27-
28-
A'的运行时间在a > 16时超过n^2,此时
29-
30-
![](http://latex.codecogs.com/gif.latex? T\(n\) = \\Theta\(n^{\\log_{4}{a}}\) < \\lg{7} = \\log_{4}{49})
31-
32-
所以最大值为48
33-
34-
35-
36-
### Exercises 4.3-3
37-
***
38-
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.)
39-
### `Answer`
40-
![](http://latex.codecogs.com/gif.latex? n^{\\log_{b}{a}} = n^{\\log_{2}{1} = 1} )
41-
42-
so the solution is Θ(lgn).
43-
44-
45-
### Exercises 4.3-4
46-
***
47-
Can the master method be applied to the recurrence
48-
![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(n/2\) + n^2 \\lg{n} )
11+
### `Answer`
12+
![](http://latex.codecogs.com/gif.latex? n^{\\log_{b}{a}} = n^{\\log_{2}{4}} = n^2)
13+
14+
a. ![](http://latex.codecogs.com/gif.latex? \\Theta\(n^2\) )
15+
16+
b. ![](http://latex.codecogs.com/gif.latex? \\Theta\(n^2 \\lg{n}\) )
17+
18+
c. ![](http://latex.codecogs.com/gif.latex? \\Theta\(n^3\) )
19+
20+
21+
### Exercises 4.3-2
22+
***
23+
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?
24+
25+
### `Answer`
26+
根据主定理,算法A的运行时间为![](http://latex.codecogs.com/gif.latex? T\(n\) = \\Theta\(\\lg{7}\)\ \\approx n^{2.8} )
27+
28+
A'的运行时间在a > 16时超过n^2,此时
29+
30+
![](http://latex.codecogs.com/gif.latex? T\(n\) = \\Theta\(n^{\\log_{4}{a}}\) < \\lg{7} = \\log_{4}{49})
31+
32+
所以最大值为48
33+
34+
35+
36+
### Exercises 4.3-3
37+
***
38+
Use the master method to show that the solution to the binary-search recurrence T(n) = T (n/2)
39+
+ Θ(1) is T(n) = Θ(lg n). (See Exercise 2.3-5 for a description of binary search.)
40+
### `Answer`
41+
![](http://latex.codecogs.com/gif.latex? n^{\\log_{b}{a}} = n^{\\log_{2}{1} = 1} )
42+
43+
so the solution is Θ(lgn).
44+
45+
46+
### Exercises 4.3-4
47+
***
48+
Can the master method be applied to the recurrence
49+
![](http://latex.codecogs.com/gif.latex? T\(n\) = 4T\(n/2\) + n^2 \\lg{n} )
4950
Why or why not? Give an asymptotic upper bound for this recurrence.
50-
51-
### `Answer`
52-
![](http://latex.codecogs.com/gif.latex? n^{\\log_{b}{a}} = n^{\\log_{2}{4}} = n^2 )
53-
54-
The problem is that it is not polynomially larger. The ratio 
55-
![](http://latex.codecogs.com/gif.latex? f\(n\) / n^{\\log_{b}{a}} = \\lg{n})
56-
is asymptotically less than
57-
![](http://latex.codecogs.com/gif.latex? n^\\epsilon ) for any positive constant
58-
![](http://latex.codecogs.com/gif.latex? \\epsilon )
59-
60-
### Exercises 4.3-5
61-
***
62-
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.
63-
64-
### `Answer`
65-
let
66-
67-
a = 1
68-
b = 2
69-
f(n) = 2 - cos(n)
70-
71-
我们需要证明
72-
73-
![](http://latex.codecogs.com/gif.latex? \\frac{n}{2}\( 2 - \\cos\(\\frac{n}{2}\)}\) < cn \\\\ ~ \\Rightarrow c > \\frac{2- \\cos\(n/2\)}{2} \\\\ ~
74-
\\Rightarrow c > \\frac{3}{2}
75-
)
76-
77-
***
78-
Follow [@louis1992](https://github.com/gzc) on github to help finish this task.
79-
51+
52+
### `Answer`
53+
![](http://latex.codecogs.com/gif.latex? n^{\\log_{b}{a}} = n^{\\log_{2}{4}} = n^2 )
54+
55+
The problem is that it is not polynomially larger. The ratio 
56+
![](http://latex.codecogs.com/gif.latex? f\(n\) / n^{\\log_{b}{a}} = \\lg{n})
57+
is asymptotically less than
58+
![](http://latex.codecogs.com/gif.latex? n^\\epsilon ) for any positive constant
59+
![](http://latex.codecogs.com/gif.latex? \\epsilon )
60+
61+
### Exercises 4.3-5
62+
***
63+
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.
64+
65+
### `Answer`
66+
let
67+
68+
a = 1
69+
b = 2
70+
f(n) = 2 - cos(n)
71+
72+
我们需要证明
73+
74+
![](http://latex.codecogs.com/gif.latex? \\frac{n}{2}\( 2 - \\cos\(\\frac{n}{2}\)}\) < cn \\\\ ~ \\Rightarrow c > \\frac{2- \\cos\(n/2\)}{2} \\\\ ~
75+
\\Rightarrow c > \\frac{3}{2}
76+
)
77+
78+
***
79+
Follow [@louis1992](https://github.com/gzc) on github to help finish this task.
80+

0 commit comments

Comments
 (0)