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
Prove that for all k ≥ 0 and all sets of real constants {ak,ak−1,...,a1,a0},
aknk+ak−1nk−1+....+a1n+a0=O(nk)
There are two distinct approaches for this problem.
[1] The case n=1:
LHSRHS=Constant.=O(1)So the statement holds.
[2] The case n≥2:
LHS=aknk+i=0∑k−1ainiSet b as:
b=max{ai:i∈Z∧0≤i≤k−1}Amount b derives a new binding below:
i=0∑k−1aini≤bi=0∑k−1niWe can apply the formula of the sum of geometric seris to this.
bi=0∑k−1ni=n−1b(nk−1)Since n≥2,
n−1b(nk−1)≤b(nk−1)So,
bi=0∑k−1ni=O(nk)Equation (3), (5) and (8) derive:
aknk+ak−1nk−1+....+a1n+a0=O(nk)Using [1] and [2], the statement holds.
Set func(m) as:
func(m)=i=0∑mak−ink−i{0≤m≤k}We'll prove func(m)=O(nk) for all m.
[1] the case m=0
func(0)=aknk=O(k)[2] induction for m′ and m′+1
Assume func(m′)=O(nk) when m=m′.
Think of func(m′+1).
func(m′+1)=func(m′)+ak−m′−1nk−m′−1The definition of O derives:
func(m′)≤c1nkforn≥n1And since n is large enough number,
nk−m′−1≤nkStatement (12)-(14) derives:
func(m′+1)≤(c1+ak−m′−1)nkforn≥n1So,
func(m′+1)=O(nk)From [1] and [2], func(m)=O(nk) is proved.
The pattern
func(k)=aknk+ak−1nk−1+....+a1n+a0=O(nk)is what we want to prove.