3. Characterizing Running Times
Exercises
3.1-1
Available in the latest revision of the IM.
3.1-2
Available in the latest revision of the IM.
3.1-3
Available in the latest revision of the IM.
3.2-1 🌟
Proves that max{f(n),g(n)}=Θ(f(n)+g(n)).
Available in the latest revision of the IM.
3.2-2
Available in the latest revision of the IM.
3.2-3
Available in the latest revision of the IM.
3.2-4
Available in the latest revision of the IM.
3.2-5
Available in the latest revision of the IM.
3.2-6
Available in the latest revision of the IM.
3.2-7 🌟
Defines asymptotic tight bounds for a function f(n,m) with two independent arguments.
Available in the latest revision of the IM.
3.3-1 🌟
Proves some properties about monotonically increasing functions f(n) and g(n).
Let m≤n. This implies that f(m)≤f(n) and g(m)≤g(n), since they are monotonically increasing functions.
If we add up these inequalities, then we get f(m)+g(m)≤f(n)+g(n), thus proving that f(n)+g(n) is monotonically increasing. If we multiply these inequalities, provided that both f and g are nonnegative, then we get f(m)⋅g(m)≤f(n)⋅g(n), thus proving that f(n)⋅g(n) is monotonically increasing.
By definition f(g(m))≤f(g(n)), so the composition f(g(n)) is also monotonically increasing.
3.3-2 🌟
Proves that ⌊αn⌋+⌈(1−α)n⌉=n for any integer n and real 0≤α≤1.
Available in the latest revision of the IM.
3.3-3 🌟
Proves that (n+o(n))k=Θ(nk) for any real constant k, thus ⌈n⌉k=Θ(nk) and ⌊n⌋k=Θ(nk).
f(n)=o(n) implies that 0≤f(n)<cn for all c>0 and n≥n0. For n≥n0 we haven≤n+f(n)<(1+c)n, thus n+o(n)=Θ(n), since we can choose any constant greater than 1 for the upper bound. Analogously, we can prove that n−o(n)=Θ(n) by simply reversing inequalities n≥n−f(n)>(1−c)n and choosing any positive constant less than 1 for the lower bound.
Consequently,
for any real constant k. As a side note, if k<0, then the inequalities of Θ are reverse of those when k>0.
By definition, n≤⌈n⌉<n+1. Let f(n)=⌈n⌉−n. Since 0≤f(n)<1⟹f(n)=o(n) (any constant is asymptotically smaller than n), this gives ⌈n⌉=n+o(n), thus ⌈n⌉k=Θ(nk). In virtually the same way, we can show that ⌊n⌋=n−o(n), so ⌊n⌋k=Θ(nk).
3.3-4
a.
b.
Observe that the largest term on the right side is 1, whilst the initial terms tend to zero as n increases. Therefore, n!=o(nn).
Here, we have an opposite situation, thus n!=ω(2n).
A weak upper bound on the factorial function is n!≤nn, so lgn!≤nlgn=O(nlgn).
Theorem 3.1 implies that lgn!=Θ(nlgn).
c.
Let f(n)=Θ(n). By definition c1n≤f(n)≤c2n for some positive constants and n≥n0.
Theorem 3.1 implies that lgf(n)=lgΘ(n)=Θ(lgn) for all n≥max{n0,1/c12,c2}.
★ 3.3-5 🌟
Proves that a function f(n) is polynomially bounded if and only if lgf(n)=O(lgn).
Available in the latest revision of the IM.
★ 3.3-6
Available in the latest revision of the IM.
3.3-7
Available in the latest revision of the IM.
3.3-8
Available in the latest revision of the IM.
3.3-9 🌟
Illustrates the symmetry property of the Θ notation by showing that klgk=Θ(n) implies k=Θ(n/lgn).
Available in the latest revision of the IM.
Problems
3-1 Asymptotic behavior of polynomials
In all subproblems, we rely on the fact (stated in the book on page 65) that for an asymptotically positive polynomial p(n) of degree d, we have p(n)=Θ(nd). Consequently, for some positive constants it holds that 0<c1nd≤p(n)≤c2nd for all n≥n0.
a.
nk≥nd for all n≥1, so 0<p(n)≤c2nd≤c2nk for all n≥n0. Thus, p(n)=O(nk).
b.
nk≤nd for all n≥1, so 0<c1nk≤c1nd≤p(n) for all n≥n0. Thus, p(n)=Ω(nk).
c.
k=d means that k≥d∧k≤d, so parts (a) and (b) apply. Theorem 3.1 implies that p(n)=Θ(nk).
d.
We fix a positive constant c and show that for sufficiently large n we have c2nd<cnk. We can rewrite this inequality as c2/c<nk−d. Apparently, it holds for all n>(c2/c)1/(k−d). Choosing n to be the maximum of this value and n0 ensures that 0<p(n)≤c2nd<cnk. As the choice of c was arbitrary, the derivation applies to all positive constants, hence p(n)=o(nk).
e.
We fix a positive constant c and show that for sufficiently large n we have c1nd>cnk. We can rewrite this inequality as c/c1<nd−k. Apparently, it holds for all n>(c/c1)1/(d−k). Choosing n to be the maximum of this value and n0 ensures that 0<cnk<c1nd≤p(n). As the choice of c was arbitrary, the derivation applies to all positive constants, hence p(n)=ω(nk).
3-2 Relative asymptotic growths
Available in the latest revision of the IM.
3-3 Ordering by asymptotic growth rates
Available in the latest revision of the IM.
3-4 Asymptotic notation properties
Available in the latest revision of the IM.
3-5 Manipulating asymptotic notation
Assume that all constants introduced in the subproblems are positive.
a.
Let g(n)=Θ(f(n)), thus 0≤c1f(n)≤g(n)≤c2f(n) for all n≥ng. Let h(n)=Θ(g(n)), so 0≤d1g(n)≤h(n)≤d2g(n) for all n≥nh. Substituting g(n) with f(n) we get 0≤d1c1f(n)≤h(n)≤d2c2f(n) for all n≥max{ng,nh}. Therefore, h(n)=Θ(f(n)), which concludes the proof.
b.
Let g(n)=Θ(f(n)), thus 0≤c1f(n)≤g(n)≤c2f(n) for all n≥ng. Let h(n)=O(f(n)), so 0≤h(n)≤df(n) for all n≥nh. By combining these inequalities we get for all n≥max{ng,nh}
Therefore, g(n)+h(n)=Θ(f(n)), which concludes the proof.
c.
Let h(n)=Θ(f(n)), thus 0≤c1f(n)≤h(n)≤c2f(n) for all n≥nh. Let q(n)=Θ(g(n)), so 0≤d1g(n)≤q(n)≤d2g(n) for all n≥nq. Adding together these inequalities we get for all n≥max{nh,nq}
Therefore, h(n)+q(n)=Θ(f(n)+g(n)), which concludes the proof.
d.
Let h(n)=Θ(f(n)), thus 0≤c1f(n)≤h(n)≤c2f(n) for all n≥nh. Let q(n)=Θ(g(n)), so 0≤d1g(n)≤q(n)≤d2g(n) for all n≥nq. Multiplying together these inequalities we get for all n≥max{nh,nq}
Therefore, h(n)⋅q(n)=Θ(f(n)⋅g(n)), which concludes the proof.
e.
3-6 Variations on O and Ω
a.
If f(n)=O(g(n)) or f(n)=Ω(g(n)) (or both), then we are done. Observe that f(n)=Ω(g(n)) implies f(n)=Ω∞(g(n)).
Suppose that g(n) cannot bound f(n). There must be infinitely many points where f(n)>cg(n), otherwise we could find a positive threshold n0 such that f(n)≤cg(n) for all n≥n0. In other words, for any n0 there is some m>n0 where f(m)>cg(m). Consequently, f(n)=Ω∞(g(n)).
b.
See Problem 3-2 row (c).
c.
As shown in part (a), one advantage of using omega infinity over standard omega is that all asymptotically nonnegative functions become asymptotically comparable. On the other hand, omega infinity cannot tell whether one function is "larger" than the other. Oscillations are permitted. Furthermore, we don't know anything about how those infinitely many points are distributed. With omega notation it is clear that the condition holds for all n≥n0. Finally, omega infinity is unknown to most software engineers.
d.
f(n)=Ω(g(n)) implies that f(n) is an asymptotically nonnegative function, hence f(n)=∣f(n)∣. Consequently, f(n)=O′(g(n)) is equivalent to f(n)=O(g(n)), so Theorem 3.1 remains valid.
e.
The proof of the corresponding analog to Theorem 3.1 is essentially the same as for the original version (see Exercise 3.2-4). The only difference is that we should use these new definitions.
3-7 Iterated functions
Available in the latest revision of the IM.
Last updated