4-3 More recurrence examples

Give asymptotic upper and lower bounds for T(n)T(n) in each of the following recurrences. Assume that T(n)T(n) is constant for sufficiently small nn. Make your bounds as tight as possible, and justify your answers.

a. T(n)=4T(n/3)+nlgnT(n) = 4T(n / 3) + n\lg n.

b. T(n)=3T(n/3)+n/lgnT(n) = 3T(n / 3) + n / \lg n.

c. T(n)=4T(n/2)+n2nT(n) = 4T(n / 2) + n^2\sqrt n.

d. T(n)=3T(n/32)+n/2T(n) = 3T(n / 3 - 2) + n / 2.

e. T(n)=2T(n/2)+n/lgnT(n) = 2T(n / 2) + n / \lg n.

f. T(n)=T(n/2)+T(n/4)+T(n/8)+nT(n) = T(n / 2) + T(n / 4) + T(n / 8) + n.

g. T(n)=T(n1)+1/nT(n) = T(n - 1) + 1 / n.

h. T(n)=T(n1)+lgnT(n) = T(n - 1) + \lg n.

i. T(n)=T(n2)+1/lgnT(n) = T(n - 2) + 1 / \lg n.

j. T(n)=nT(n)+nT(n) = \sqrt nT(\sqrt n) + n

a. By master theorem, T(n)=Θ(nlog34)T(n) = \Theta(n^{\log_3 4}).

b.

By the recursion-tree method, we can guess that T(n)=Θ(nlog3log3n)T(n) = \Theta(n\log_3\log_3 n).

We start by proving the upper bound.

Suppose k<n    T(k)cklog3log3kkk < n \implies T(k) \le ck \log_3\log_3 k - k, where we subtract a lower order term to strengthen our induction hypothesis.

It follows that

T(n)3(cn3log3log3n3n3)+nlgncnlog3log3nn+nlgncnlog3log3n, \begin{aligned} T(n) & \le 3 (c \frac{n}{3} \log_3\log_3 \frac{n}{3} - \frac{n}{3}) + \frac{n}{\lg n} \\ & \le c n \log_3\log_3 n - n + \frac{n}{\lg n} \\ & \le c n \log_3\log_3 n, \end{aligned}

if nn is sufficiently large.

The lower bound can proved analogously.

c. By master theorem, T(n)=Θ(n2.5)T(n) = \Theta(n^{2.5}).

d. It is Θ(nlgn)\Theta(n\lg n). The subtraction occurring inside the argument to TT won't change the asymptotics of the solution, that is, for large nn the division is so much more of a change than the subtraction that it is the only part that matters. once we drop that subtraction, the solution comes by the master theorem.

e. By the same reasoning as part (b), the function is O(nlgn)O(n\lg n) and Ω(n1ϵ)\Omega(n^{1 - \epsilon}) for every ϵ\epsilon and so is O~(n)\tilde O(n), see Problem 3-5.

f. We guess T(n)cnT(n) \le cn,

T(n)=T(n/2)+T(n/4)+T(n/8)+n78cn+ncn. \begin{aligned} T(n) & = T(n / 2) + T(n / 4) + T(n / 8) + n \\ & \le \frac{7}{8}cn + n \le cn. \\ \end{aligned}

where the last step holds for c8c \ge 8.

g. Recall that χA\chi_A denotes the indicator function of AA. We see that the sum is

T(0)+j=1n1j=T(0)+1n+1j=1n+1χj,j+1(x)jdx.T(0) + \sum_{j = 1}^n \frac{1}{j} = T(0) + \int_1^{n + 1}\sum_{j = 1}^{n + 1} \frac{\chi_{j, j + 1}(x)}{j}dx.

Since 1x\frac{1}{x} is monatonically decreasing, we have that for every iZ+i \in \mathbb Z^+,

supx(i,i+1)j=1n+1χj,j+1(x)j1x=1i1i+1=1i(i+1).\text{sup}_{x \in (i, i + 1)} \sum_{j = 1}^{n + 1} \frac{\chi_{j, j + 1}(x)}{j} - \frac{1}{x} = \frac{1}{i} - \frac{1}{i + 1} = \frac{1}{i(i + 1)}.

Our expression for T(n)T(n) becomes

T(N)=T(0)+1n+1(1x+O(1x(x+1)))dx.T(N) = T(0) + \int_1^{n + 1} \Big(\frac{1}{x} + O(\frac{1}{\lfloor x \rfloor(\lfloor x \rfloor + 1)})\Big)dx.

We deal with the error term by first chopping out the constant amount between 1 and 2 and then bound the error term by O(1x(x1))O(\frac{1}{x(x - 1)}) which has an anti-derivative (by method of partial fractions) that is O(1n)O(\frac{1}{n}),

T(N)=1n+1dxx+O(1n)=lgn+T(0)+12+O(1n). \begin{aligned} T(N) & = \int_1^{n + 1} \frac{dx}{x} + O(\frac{1}{n}) \\ & = \lg n + T(0) + \frac{1}{2} + O(\frac{1}{n}). \end{aligned}

This gets us our final answer of T(n)=Θ(lgn)T(n) = \Theta(\lg n).

h. We see that we explicity have

T(n)=T(0)+j=1nlgj=T(0)+1n+1j=1n+1χ(j,j+1)(x)lgjdx. \begin{aligned} T(n) & = T(0) + \sum_{j = 1}^n \lg j \\ & = T(0) + \int_1^{n + 1} \sum_{j = 1}^{n + 1} \chi_{(j, j + 1)}(x) \lg j dx. \end{aligned}

Similarly to above, we will relate this sum to the integral of lgx\lg x.

supx(i,i+1)j=1n+1χ(j,j+1)(x)lgjlgx=lg(j+1)lgj=lg(j+1j).\text{sup}_{x \in (i, i + 1)} \sum_{j = 1}^{n + 1} \chi_{(j, j + 1)}(x) \lg j - \lg x = \lg(j + 1) - \lg j = \lg \Big(\frac{j + 1}{j}\Big).

Therefore,

T(n)inlg(x+2)+lgxlg(x+1)dx(1+O(1lgn))Θ(nlgn). \begin{aligned} T(n) & \le \int_i^n \lg(x + 2) + \lg x - \lg(x + 1)dx \\ & (1 + O(\frac{1}{\lg n})) \Theta(n\lg n). \end{aligned}

i. See the approach used in the previous two parts, we will get T(n)=Θ(nlgn)T(n) = \Theta(\frac{n}{\lg n}).

j. Let ii be the smallest ii so that n12i<2n^{\frac{1}{2^i}} < 2. We recall from a previous problem (3-6.e) that this is lglgn\lg\lg n Expanding the recurrence, we have that it is

T(n)=n112iT(2)+n+nj=1i=Θ(nlglgn). \begin{aligned} T(n) & = n^{1 - \frac{1}{2^i}}T(2) + n + n\sum_{j = 1}^i \\ & = \Theta(n\lg\lg n). \end{aligned}