Skip to content

Latest commit

 

History

History
102 lines (74 loc) · 3.9 KB

4.1.md

File metadata and controls

102 lines (74 loc) · 3.9 KB

Exercises 4.1-1


Show that the solution of ![](http://latex.codecogs.com/gif.latex? T(n) = T(\lceil n/2 \rceil) + 1) is O(lg n).

Answer

我们猜想 ![](http://latex.codecogs.com/gif.latex? T(n) \le c\lg(n-2) )

![](http://latex.codecogs.com/gif.latex? T(n) = T(\lceil n/2 \rceil) + 1 \le T(n/2+1) +1 \\ ~ \hspace{15 mm} \le c\lg(n/2-1)+1 \\ ~ \hspace{15 mm} =clg(n-2) -c\lg2 + 1 \\ ~ \hspace{15 mm} \le clg(n-2) )

Exercises 4.1-2


We saw that the solution of ![](http://latex.codecogs.com/gif.latex? T(n) = 2T(\lfloor n/2 \rfloor) + n) is O(n lg n). Show that the solution of this recurrence is also Ω(n lg n). Conclude that the solution is Θ(n lg n).

Answer

我们假设![](http://latex.codecogs.com/gif.latex? T(n) \ge cn\lg{n} )

![](http://latex.codecogs.com/gif.latex? T(n) = 2T(\lfloor n/2 \rfloor) + n \\ ~ \hspace{15 mm} \ge cn(\lg{n} - \lg{2})+n \\ ~ \hspace{15 mm} =cn\lg{n} +(1-c\lg{2})n \\ ~ \hspace{15 mm} \ge cnlg(n) \\ ~ \hspace{15 mm} for ~ 1-c\lg{2} < 0 )

Exercises 4.1-3


Show that by making a different inductive hypothesis, we can overcome the difficulty with the boundary condition T (1) = 1 for the recurrence (4.4) without adjusting the boundary conditions for the inductive proof.

Answer

我们假设 ![](http://latex.codecogs.com/gif.latex? T(n) \le n\lg{n}+n)

![](http://latex.codecogs.com/gif.latex? T(n) \le 2(c\lfloor n/2 \rfloor \lg(\lfloor n/2 \rfloor) + \lfloor n/2 \rfloor) + n \\ ~ \hspace{15 mm} \le 2c(n/2)\lg(n/2) + 2(n/2) + n \\ ~ \hspace{15 mm} \le cn\lg(n/2) + 2n \\ ~ \hspace{15 mm} \le cn\lg{n} - \lg{2}cn + 2n \\ ~ \hspace{15 mm} \le cn\lg{n} + (2-c)n \\ ~ \hspace{15 mm} \le cn\lg{n} + n ~~~~~~~~~~~~ for ~ c \ge 1 )

Exercises 4.1-4


Show that Θ(n lg n) is the solution to the "exact" recurrence (4.2) for merge sort.

Answer

我们假设![](http://latex.codecogs.com/gif.latex? T(n) \ge cn\lg{n} )

![](http://latex.codecogs.com/gif.latex? T(n) \ge 2T(n/2) + kn \\ ~ \hspace{15 mm} =cn\lg{n} +(k-c\lg{2})n \\ ~ \hspace{15 mm} \ge cn\lg{n} ~~~~~~ if ~ k \le c\lg{2} )

我们假设![](http://latex.codecogs.com/gif.latex? T(n) \le c(n-2)\lg(n-2) )

![](http://latex.codecogs.com/gif.latex? T(n) \le T(n/2+1) + T(n/2) + kn \\ ~ \hspace{15 mm} \le c(n-2)\lg(\frac{n-2}{2}) + kn \\ ~ \hspace{15 mm} = c(n-2)\lg(n-2) +kn - c\lg{2}(n-2) \\ ~ \hspace{15 mm} \le c(n-2)\lg(n-2) ~~~~~~~~if~~kn \le c\lg{2}(n-2) )

Exercises 4.1-5


Show that the solution to ![](http://latex.codecogs.com/gif.latex? T(n) = 2T(\lfloor n/2 \rfloor + 17) + n ) is O(n lg n).

Answer

我们假设![](http://latex.codecogs.com/gif.latex? T(n) \le c(n-a)\lg(n-a) )

![](http://latex.codecogs.com/gif.latex? T(n) \le 2c(\lfloor n/2 \rfloor + 17 - a)\lg(\lfloor n/2 \rfloor + 17-a) + n\\ ~ \hspace{15 mm} \le 2c(n/2 +1+ 17 - a)\lg( n/2 +1+ 17-a) + n \\ ~ \hspace{15 mm} \le c(n+36-2a)\lg(\frac{n+36-2a}{2})+n \\ ~ \hspace{15 mm} \le c(n+36-2a)\lg(n+36-2a) - c(n+36-2a)+n \\ ~ \hspace{15 mm} \le c(n+36-2a)\lg(n+36-2a) ~~~if ~~ c > 1 \\ ~ \hspace{15 mm} \le c(n-a)\lg(n-a) ~~~~if ~~ a \ge 36 )

Exercises 4.1-6


Solve the recurrence ![](http://latex.codecogs.com/gif.latex? T(n) = 2T(\sqrt{n})+1 ) by making a change of variables. Your solution should be asymptotically tight. Do not worry about whether values are integral.

Answer

设n = lgn,得到新的递归式

![](http://latex.codecogs.com/gif.latex? T(2^n) = 2T(2^{n/2}) + 1)

再令S(n) = T(2^n)可以得到

![](http://latex.codecogs.com/gif.latex? S(n) = S2(m/2) + 1)

按照前面的方法解这个递归式即可


Follow @louis1992 on github to help finish this task.