Tutorial 1
1.8) Use the definition to show, that
f(n)=2⋅5n+1000⋅n4
is f(n)∈Θ(5n).
Solution
We need to show, that
(∃c1,c2∈R+)(∃n0∈N)(∀n>n0)(c1⋅5n≤2⋅5n+1000⋅n4≤c2⋅5n).
We can choose c1 to be 1, since
5n0≤2⋅5n+1000⋅n4≤5n+1000⋅n4∣−5n
is true for all n≥1.
Second part of inequality gives us
2⋅5n+1000⋅n41000⋅n4≤c2⋅5n≤(c2−2)⋅5n∣−2⋅5n
If n4≤5n, than
1000⋅5nn4≤1000⋅1≤(c2−2),
which gives us c2≥1002.
Limit: use l’hopital 5 times, eventually we’ll get 1/5n.
1.9 Let there be three positive functions f(n), g(n) and h(n). Prove that
f(n)∈O(g(n))∧g(n)∈O(h(n))⇒f(n)∈O(h(n))
Solution
We know, that
(∃c∈R+)(∃n1∈N)(∀n≥n1)(f(n)≤c⋅g(n))
and
(∃d∈R+)(∃n2∈N)(∀n≥n2)(g(n)≤d⋅h(n)).
Therefore,
f(n)≤c⋅g(n)≤(c⋅d)⋅h(n).
Setting n3=max{n1,n2} and e=c⋅d gives us
(∃e∈R+)(∃n3∈N)(∀n≥n3)(f(n)≤e⋅h(n)).
which is exactly the definition of f(n)∈O(h(n)).
1.10 Prove following: Let the f1(n), f2(n) and h(n) be non-negative functions, such that
f1(n)∈Θ(h(n))∧f2(n)∈Θ(h(n)⋅log2n)
then (f1+f2)(n)∈Θ(h(n)log2n)
Solution
Sum of functions is defined as
(f1+f2)(n)=f1(n)+f2(n).
We know that
(∃c1,c2∈R+)(∃n0∈N)(∀n>n0)(c1⋅h(n)≤f1(n)≤c2⋅h(n)).
and
(∃d1,d2∈R+)(∃n1∈N)(∀n>n1)(d1⋅h(n)log2n≤f2(n)≤d2⋅h(n)log2n).
meaning that
f1(n)+f2(n)≤(c2⋅h(n))+(d2⋅h(n)⋅log2n))
f1(n)+f2(n)≤(c2+d2⋅log2n)⋅h(n)
Since log2(n)≥1 for n≥2,
(c2+d2⋅log2n)⋅h(n)≤(c2+d2)⋅log2(n)⋅h(n)
is truth.
f1(n)+f2(n)≥c1⋅h(n)+d1⋅log2n⋅h(n)
removing c1⋅h(n) lowers the right side of the inequality, since all the terms are positive. Thus
f1(n)+f2(n)≥d1⋅log2n⋅h(n).
Together, we get
(∃e1,e2∈R+)(∃n2∈N)(∀n>n2)(e1⋅h(n)log2n≤(f1+f2)(n)≤e2⋅h(n)log2n),
where e1=d1, e2=c2+d2 and n2=max{n0,n1,2}. Which is by definition what we wanted to prove.