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)+nlgn.
b. T(n)=3T(n/3)+n/lgn.
c. T(n)=8T(n/2)+n3n.
d. T(n)=2T(n/2−2)+n/2.
e. T(n)=2T(n/2)+n/lgn.
f. T(n)=T(n/2)+T(n/4)+T(n/8)+n.
g. T(n)=T(n−2)+1/n.
h. T(n)=T(n−1)+lgn.
i. T(n)=T(n−2)+1/lgn.
j. T(n)=nT(n)+n.
a
nlogba=nlog35f(n)=nlgn=O(nlogba−log3(5/4))T(n)=Θ(nlogba)=Θ(nlog35)
b
⟹T(n)3(31)p=1p=1=Θ(np(1+∫1nxp+1f(x)dx))=Θ(n1(1+∫1nx2x/lgxdx))=Θ(n1(1+∫1nxlgx1dx))=Θ(n1(1+[lglgx]1n))=Θ(nlglgn)
- Tips: if f(1)=∞, we will assume T(1)=f(1)=Θ(1)
c
nlogba=nlog28=n3f(n)=n7/2=Ω(nlogba+1/2)af(n/b)=2−1/2(n7/2)≤2−1/2f(n)T(n)=Θ(f(n))=Θ(n7/2)
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)
e
⟹T(n)2(21)p=1p=1=Θ(np(1+∫1nxp+1f(x)dx))=Θ(n1(1+∫1nx2x/lgxdx))=Θ(n1(1+∫1nxlgx1dx))=Θ(n1(1+[lglgx]1n))=Θ(nlglgn)
f
T(n)(21)p+(41)p+(81)p=10.5<p<1=Θ(np(1+∫1nxp+1f(x)dx))=Θ(np(1+∫1nxp+1xdx))=Θ(np(1+∫1nxp1dx))=Θ(np(1+[x1−p]1n))=Θ(n)
g
T(n)=21i=1∑n(i1)≤21+1/2∫1n−1x1=Θ(21+21lg(n−1))=Θ(lgn)
h
T(n)=T(n−1)+lgn
T(n)=i=1∑nlgi=lg(n!)=Θ(nlgn)
i
T(n)T(n)T(n)=1+i=2∑nlgi1=Ω(∑i=2nlgnn2)=Ω(lgnn)=O(i=2∑n−1lg21+i=n∑nlgn1)=O(n+lgnn)=Θ(n)
j
depth: lglgn+1, leaves: n
total cost of over all nodes at depth i, for i=0,1,...,lglgn−1, is n
T(n)=Θ(nlglgn)