Table of Contents
This series is my solutions for algorithm exercises in'The Algorithm Design Manual' 3rd edition.
It's my solutions, not model answers, so if you find some mistakes or more sophisticated solutions, please post in comment area below.
Here
For each of the following expressions f(n) find a simple g(n) such that f(n)=Θ(g(n)).
(a)(b)(c)(d)f(n)=i=1∑ni1f(n)=i=1∑n⌈i1⌉f(n)=i=1∑nlogif(n)=logn!As a graph below shows, the summation can be regarded as an uppersum of a function y=x1 and bound by two reciprocal functions.
And the next inequation holds:
∫1nx1dx≤i=1∑ni1≤∫2n+1x−11dx+1Think of solving Left Hand Side and Right hand Side of the above formula.
∫1nx1dx=[ln∣x∣]1n=lnn ∫2n+1x−11dx+1=[ln∣x−1∣]2n+1+1=lnn+1So, f(n)'s boundation and function g(n) is:
f(n)=Θ(logn) g(n)=logno<i1<1for{i∈N}So,
⌈i1⌉f(n)=1=i=1∑n⌈i1⌉=nSo function g(n) is:
g(n)=nFrom similar analysis as promlem(a),
∫1nlogxdx<i=1∑nlogi<∫2n+1log(x−1)dx+1Think of LHS and RHS.
For simplicity, we think abount lnx rather than logx(the asymptotical order is same).
LHS=∫1nlnxdx=[xlnx]1n−∫1n1dx=nlnn+Θ(n)=Θ(nlogn) RHS=∫2n+1ln(x−1)dx+1=[xln(x−1)]2n+1−∫2n+1(1−n−11)dx+1=Θ(nlnn)+Θ(n)+Θ(lnn)+Θ(1)=Θ(nlogn)So,
g(n)=nlognThe product as an anti-logarithm can be distributed into the summation of logarithm.
f(n)=logn!=i=1∑nlogiThe shape of the formula is exactly the same as that in the problem (c).
So the result is also the same.