Skip to content

4-4 More recurrence examples

Give asymptotically tight upper and lower bounds for T(n) in each of the following recurrences. Justify your answers.

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

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

c. T(n)=8T(n/2)+n3nT(n)= 8T(n/2)+n^3\sqrt{n}.

d. T(n)=2T(n/22)+n/2T(n)=2T(n/2-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(n2)+1/nT(n)=T(n-2)+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{n}T(\sqrt{n})+n.

a

nlogba=nlog35f(n)=nlgn=O(nlogbalog3(5/4))T(n)=Θ(nlogba)=Θ(nlog35) \begin{aligned} n^{\log_{b}{a}} = n^{\log_{3}{5}}\cr f(n) = n\lg{n} = O(n^{\log_{b}{a}-\log_{3}{(5/4)}})\cr T(n)=\Theta({n^{\log_{b}{a}}})=\Theta(n^{\log_{3}{5}})\cr \end{aligned}

b

3(13)p=1    p=1T(n)=Θ(np(1+1nf(x)xp+1dx))=Θ(n1(1+1nx/lgxx2dx))=Θ(n1(1+1n1xlgxdx))=Θ(n1(1+[lglgx]1n))=Θ(nlglgn) \begin{aligned} & 3(\frac{1}{3})^p=1\cr \implies & p = 1\cr T(n) & =\Theta(n^p(1+\int_{1}^{n}\frac{f(x)}{x^{p+1}}dx))\cr & = \Theta(n^1(1+\int_{1}^{n}\frac{x/\lg x}{x^{2}}dx))\cr & = \Theta(n^1(1+\int_{1}^{n}\frac{1}{x^{}\lg x}dx))\cr & = \Theta(n^1(1+\left[\lg\lg x\right]_{1}^{n}))\cr & = \Theta (n\lg\lg n)\cr \end{aligned}

  • Tips: if f(1)=f(1)=\infty, we will assume T(1)=f(1)=Θ(1)T(1)=f(1)=\Theta(1)

c

nlogba=nlog28=n3f(n)=n7/2=Ω(nlogba+1/2)af(n/b)=21/2(n7/2)21/2f(n)T(n)=Θ(f(n))=Θ(n7/2) \begin{aligned} n^{\log_{b}{a}} = n^{\log_{2}{8}}=n^{3}\cr f(n) = n^{7/2} = \Omega(n^{\log_{b}{a}+1/2})\cr af(n/b)=2^{-1/2}(n^{7/2})\leq 2^{-1/2}f(n)\cr T(n)=\Theta(f(n))=\Theta(n^{7/2})\cr \end{aligned}

d

f(n)=n/2 satisfies polynomial-growth conditionT(n)=2T(n/2)+n/2nlogba=nlog22=nf(n)=n/2=Θ(nlogbalg0n)T(n)=Θ(nlogbalgn)=Θ(nlgn) \begin{aligned} f(n)=n/2 \text{ satisfies polynomial-growth condition}\cr T(n)=2T(n/2)+n/2\cr n^{\log_{b}{a}} = n^{\log_{2}{2}}=n^{}\cr f(n) = n^{}/2 = \Theta(n^{\log_{b}{a}}\lg^{0}n)\cr T(n)=\Theta(n^{\log_{b}{a}}\lg n)=\Theta(n\lg n)\cr \end{aligned}

e

2(12)p=1    p=1T(n)=Θ(np(1+1nf(x)xp+1dx))=Θ(n1(1+1nx/lgxx2dx))=Θ(n1(1+1n1xlgxdx))=Θ(n1(1+[lglgx]1n))=Θ(nlglgn) \begin{aligned} & 2(\frac{1}{2})^p=1\cr \implies & p = 1\cr T(n) & =\Theta(n^p(1+\int_{1}^{n}\frac{f(x)}{x^{p+1}}dx))\cr & = \Theta(n^1(1+\int_{1}^{n}\frac{x/\lg x}{x^{2}}dx))\cr & = \Theta(n^1(1+\int_{1}^{n}\frac{1}{x^{}\lg x}dx))\cr & = \Theta(n^1(1+\left[\lg\lg x\right]_{1}^{n}))\cr & = \Theta(n\lg\lg n)\cr \end{aligned}

f

(12)p+(14)p+(18)p=10.5<p<1T(n)=Θ(np(1+1nf(x)xp+1dx))=Θ(np(1+1nxxp+1dx))=Θ(np(1+1n1xpdx))=Θ(np(1+[x1p]1n))=Θ(n) \begin{aligned} & (\frac{1}{2})^{p}+(\frac{1}{4})^{p}+(\frac{1}{8})^{p}=1\cr & 0.5<p<1\cr T(n) & =\Theta(n^p(1+\int_{1}^{n}\frac{f(x)}{x^{p+1}}dx))\cr & = \Theta(n^p(1+\int_{1}^{n}\frac{x}{x^{p+1}}dx))\cr & = \Theta(n^p(1+\int_{1}^{n}\frac{1}{x^{p}}dx))\cr & = \Theta(n^p(1+\left[x^{1-p}\right]_{1}^{n}))\cr & = \Theta(n)\cr \end{aligned}

g

T(n)=12i=1n(1i)12+1/21n11x=Θ(12+12lg(n1))=Θ(lgn) \begin{aligned} T(n) & = \frac{1}{2}\sum_{i=1}^{n}(\frac{1}{i})\cr & \leq \frac{1}{2}+1/2\int_{1}^{n-1}\frac{1}{x}\cr & = \Theta(\frac{1}{2}+\frac{1}{2}\lg (n-1))\cr & = \Theta(\lg n)\cr \end{aligned}

h

T(n)=T(n1)+lgnT(n)=T(n-1)+\lg n T(n)=i=1nlgi=lg(n!)=Θ(nlgn) \begin{aligned} T(n) & = \sum_{i=1}^{n}\lg i\cr & = \lg(n!)\cr & = \Theta(n\lg n)\cr \end{aligned}

i

T(n)=1+i=2n1lgi=Ω(n2i=2nlgn)=Ω(nlgn)T(n)=O(i=2n11lg2+i=nn1lgn)=O(n+nlgn)T(n)=Θ(n) \begin{aligned} T(n) & =1+\sum_{i=2}^{n}\frac{1}{\lg i}\cr & = \Omega(\frac{n^2}{\sum_{i=2}^{n}\lg n})\cr & = \Omega(\frac{n}{\lg n})\cr T(n) & =O(\sum_{i=2}^{\sqrt{n}-1}\frac{1}{\lg 2}+\sum_{i=\sqrt{n}}^{n}\frac{1}{\lg \sqrt{n}})\cr & = O(\sqrt{n}+\frac{n}{\lg n})\cr T(n) & = \Theta(n)\cr \end{aligned}

j

depth: lglgn+1\lg\lg n+1, leaves: nn

total cost of over all nodes at depth ii, for i=0,1,...,lglgn1i=0,1,...,\lg \lg n-1, is n

T(n)=Θ(nlglgn) \begin{aligned} T(n)=\Theta(n\lg\lg n)\cr \end{aligned}