This example demonstrates that g(N)=O(f(N)) can encompass functions that are asymptotically negative. Certain references, like CLRS's Introduction to Algorithms, restrict g(N) to nonnegative functions and employ a specific notation, O', to remove this limitation within O-notation.
We start by factoring N/(N+1)=1+(−1/(N+1)). Let’s show that the second summand is O(1/N)
1/N−1/(N+1)=N+1N<1 for all N≥0,
therefore, N/(N+1)=1+O(1/N). We also have
N→∞lim1−1/NN/(N+1)=1,
hence, N/(N+1)∼1−1/N.
Exercise 3
N→∞limNβNα=N→∞limNβ−α1=0,when α<β.
Therefore, Nα=o(Nβ) for α<β.
Exercise 4
The O- and o-notations provide ways to express upper bounds (with o being the stronger assertion). Consequently, g(N)=o(f(N))⟹g(N)=O(f(N)). By combining the results from the previous two exercises, for r≥0 fixed, we can conclude that (see also section 4.3 of the book)
Instead of relying on basic algebraic manipulations involving the O-notation, we can represent the numerator of (rN) as a polynomial P(N)=N(N−1)⋯(N−r+1). Since there are r terms in this product, multiplying the N from each term gives us a leading term of Nr. To find the next term (the coefficient of Nr−1), we sum the constant terms from each factor
Sum of constants=−(0+1+2+⋯+(r−1))=−2(r−1)r.
Thus, the numerator expands to
P(N)=Nr−2r(r−1)Nr−1+…(lower order terms).
Dividing by r! gives
(rN)=r!Nr−2⋅r!r(r−1)Nr−1+…
The first term is our leading term. All subsequent terms form a polynomial of degree r−1. Therefore, their sum is O(Nr−1) (see also the previous exercise). An analogous reasoning applies for the case (rN+r).
The cosine function oscillates between -1 and 1, thus as N→∞ we have 1/(2+cosN)∈[1/3,1]. Clearly, it’s bounded from above, but doesn’t tend to 0. Therefore, it is O(1) but not o(1).
Exercise 7
The definition from the book "...we often refer informally to a quantity as being exponentially small if it is smaller than any negative power of N—that is, O(1/NM) for any positive M." is imprecise. Namely, the word "smaller" pertains to an asymptotic property of a decay, so instead of O- it should use o-notation.
In the last line MlnN=o(log2N), since after cancelling one logarithm on both sides, we are left with a constant term "against" a logarithm that grows to infinity. Observe that we don’t care about the base of a logarithm on the RHS, as it’s just a constant multiple of a natural logarithm. Therefore, e−log2N is exponentially small.
By employing the same reasoning as above, we see that now lnlogn grows faster than any constant. Therefore, (logN)−logN is also exponentially small.
Exercise 9 🌟
This exercise shows why focusing on an asymptotically most significant term is beneficial. As the calculation shows, it’s a reliable estimator of the performance for sufficiently large problem sizes.
Let f(N) be exponentially small, meaning for every M>0, f(N)=o(N−M). For any polynomialg(N)=O(Nd), where d≥0 is the degree of the polynomial, we can choose M′=M+d, such that f(N)g(N)=o(N−M′)O(Nd)=o(N−M). This concludes the proof.
Exercise 11 🌟
Chapter 2 of the book explains the Master Theorem with a note that floors/ceilings can be ignored without breaking the asymptotic result. The term a⌊n/2⌋+O(1) implies that every time we recurse, we introduce a small constant error O(1) due to potential rounding errors. This gives
In a binary recursion tree, where every internal node has 2 children, the number of nodes doubles at every level. The sum of this error across the whole tree is proportional to the number of nodes in the tree
Total Error=k=0∑lgn2k⋅O(1)=O(n).
Consequently, an=(Ideal Solution)+O(n), where ideal solution denotes the case when n is a power of two. We’ll derive these ideal solutions and see that the extra O(n) error has no significance on them.
an=2an/2+O(n) essentially falls under case 2 of the Master Theorem. We have lgn levels in the recursion tree taking O(n) work per level. Therefore, an=O(nlogn). We cannot use Θ-notation because the term O(n) allows for the driving function to be 0 or even negative (see the next exercise).
an=2an/2+o(n) can also be handled using the summation approach. We have lgn levels in the recursion tree taking o(n) work per level. Therefore, an=o(nlogn).
an∼2an/2+n means that an=2an/2+n+o(n). Dividing by n and letting bn=an/n yields bn=bn/2+1+o(1). Iterating this recurrence gives bn=b0+lgn+o(lgn), so an=nlgn+o(nlgn). Therefore, an∼nlgn.
Handling the base cases demands Θ(n) time, so for cases 1 and 2 we also have a lower bound an=Ω(n).
Exercise 12
This is a continuation of the previous exercise, where the first case is already covered:
an=2an/2+Θ(n) entails that an=Θ(nlogn).
an=2an/2+Ω(n) entails that an=Ω(nlogn).
Exercise 13
Both a(x) and b(x) grow like xα, and the additive perturbation c in the argument of b(x) becomes asymptotically negligible. To see this, we just need to iterate the recurrences until hitting the base cases.
For a(x) the recursion unfolds as
a(x)=f(x)+f(x/β)+f(x/β2)+⋯+f(x/βk),
where x/βk<1 eventually, so the sum terminates. Since f(x)=xα, each term is (x/βi)α, and the sum behaves like a convergent infinite geometric series as x→∞
a(x)=xαi=0∑logβxβ−αi∼βα−1βαxα.
For b(x) the recurrence is slightly perturbed
b(x)=f(x)+f(x/β+c)+f(x/β2+c(1+1/β))+⋯
But asymptotically x/βi+O(1)∼x/βi, so each term in the sum is still ∼(x/βi)α, and the same geometric series argument applies.
A generalization of this exercise is part of the Akra-Bazzi method, which should be included in the toolbox of techniques for finding asymptotic approximations of recurrences.
Thus, β=2, ν=1, g′(1/2)=−2 and f(1/2)=1, so the approximate solution is an∼2n as before.
The text of the exercise repeats the initial conditions, so we assume that it refers to the example given in section 3.3 of the book with a0=0 and a1=1.
g(z)f(z)=(1−2z)2z.
Thus, β=2, ν=2, g′′(1/2)=8 and f(1/2)=1/2, so the approximate solution is an∼n2n−1 as before.
We have two poles of same modulus, so we must take the one of highest multiplicity. Thus, β=1, ν=2, g′′(1)=4 and f(1)=1, so the approximate solution is an∼n/2 as expected.
Observe that P(1)=1−t=0 for t>1, thus z=1 isn’t a root. Consequently, the roots of P(z) are exactly the roots of Q(z), excluding z=1. A polynomial Q(z) has multiple roots only if Q(z) and its derivative Q′(z) share a root.
Q′(z)=(t+1)zt−2tzt−1=zt−1[(t+1)z−2t].
The unique roots of the derivative are z=0 and z=t+12t. Apparently Q(0)=1, so z=0 isn’t shared. For the other candidate, we have
We would need (t+12t)tt+12=1. But for all t>1, t+12t>1, so the power term grows exponentially. Therefore, all roots of P(z) are distinct.
Showing that Exactly One Root has Modulus > 1
Because the coefficients of P(z) are real, the singleton dominant root must be a real number. We can verify that P(1)=1−t<0 and P(2)=1>0, hence by the intermediate value theorem, there is a real root in (1,2).
By using Rouché's theorem on the unit disk, we show that the remaining t−1 roots of P(z) lie inside the unit circle ∣z∣≤1; this theorem relates the number of zeros of two functions, f(z) and f(z)+g(z), inside a region. Let’s rearrange the terms of Q(z)
f(z)−2zt+g(z)zt+1+1.
We focus our attention on a circle of radius ∣z∣=1+ϵ (where ϵ is a very small positive number). The magnitudes of our functions on the contour line are:
∣f(z)∣=∣−2zt∣=2(1+ϵ)t≈2+2tϵ
∣g(z)∣≤∣z∣t+1+1=(1+ϵ)t+1+1≈1+(1+(t+1)ϵ)=2+(t+1)ϵ
Since t>1, we have 2t>t+1, thus ∣f(z)∣>∣g(z)∣. By Rouché's theorem, the polynomial Q(z)=f(z)+g(z) has the same number of roots inside the circle ∣z∣=1+ϵ as f(z).
f(z) has a root of multiplicity t at the origin (z=0). Therefore, Q(z) has exactly t roots strictly inside the circle ∣z∣<1+ϵ. Consequently, P(z) has exactly t−1 roots inside the same disk; recall that we must exclude z=1, which was counted for Q(z).
Exercise 18
We need to apply the result from the previous exercise. Since the recurrence formula reflects P(z)=zt–zt–1–…–z–1, we know there is a single root β (approaches 2 as t→∞) of highest modulus. According to Theorem 4.1, FN[t]∼CβN. Wikipedia describes this variant as n-acci sequence and provides a precise expression for the leading term.
A more streamlined version would be stated in terms of 1/N, since N−1∼N. By taking x=1/N in the geometric series, we get 1/(N−1)=1/N+1/N2+1/N3+O(N−4). We need to replace the factors involving 1/(N−1) in the above series with the given expansion of 1/(N−1). This gives
N−1NlnN−1N=N1+2N23+6N311+O(N41).
Exercise 24
Let x=0.1, so ln0.9=ln(1−0.1). By using Table 4.2 and expanding each function to within O(x5), we get
2+2x+x2/2+x3/2+x4/3+O(x5).
We should be careful when summing up the terms of a logarithm, due to subtraction and negative value of x. After substituting x into the above expression, we find that the result is 2.20553, which is to within 10−4.
Exercise 25
Observe that 9801=992=(100−1)2, so
98011=(100−1)21=104(1−0.01)21.
Table 4.2 has an expansion of the geometric series. By differentiating both sides of that identity, we get
Vertical bars are used to delineate slots, each of which is populated with successive natural numbers. Each slot accommodates two digits, enabling this sequence to progress up to the number 97. In other words, we can predict digits in this manner within 100−196. The pattern breaks at the slot with 98, as illustrated below:
The carry from the 100th term impacts the slots containing 98 and 99.
We can generalize this to generate sequences of integers padded to n digits
(10n−1)21=102n(1−10−n)21.
For example, 1/81=0.012345679… (8 is missing due to the carry-over from 9).
Exercise 26
If we apply the nonasymptotic version of Stirling’s formula to describe (N2N), we get
The specific bounds implied by the absolute formula are
7.4749709≤H^1000≤7.4949709
The specific bounds implied by the relative formula are
0≤H^1000≤16.9077553
The LHS is truncated to zero as a negative lower bound is meaningless. The RHS is huge, since the assumed constant is too large. In a relative formula, we expect h(N)=o(1) that should decay rapidly even for small problem sizes.
Recall that O(h(N)) with a constant ∣C∣<10 covers the range ±Ch(N).
Exercise 28
The exact value is T10=16,796.
The specific bounds implied by the relative formula are
0≤T^10≤37,416.
Exercise 29
Let’s split the original recurrence at the threshold value M>0
The derivation uses the gamma function and exponential integral to craft the "closed-form" solution. The last line follows after employing the substitution u=z−N.
Of course, we can make f(N)=S(N) or construct a function that can be approximated by using few terms of S(N). Let’s use expansion of the geometric series from Table 4.2 with x=1/N. This gives
There is a complementary ω-notation that reflects the opposite relationship compared to the o-notation. It denotes a strict lower bound (grows strictly faster than). We use it in our list below:
eN=O(N2) is false, since limN→∞N2eN=∞. We can say that eN=ω(N2).
eN=O(2N) is false (see Exercise 9). We can say that eN=ω(2N).
2−N is exponentially small, so 2−N=O(1/N10) is true (see Exercise 7).
NlnN=O(eln2N) is true, since NlnN=elnNlnN=eln2N.
Exercise 32
The Taylor expansion of ex in terms of x=1/(N+1) is (see Table 4.2)
eN+11=1+N+11+2(N+1)21+O((N+1)31).
We can provide a more streamlined version in terms of 1/N (see also Exercise 23). The book shows the expansion of 1/(N+1)=1/N−1/N2+O(N−3). We need to replace the factors involving 1/(N+1) in the expansion of e1/(N+1) with the given expansion of 1/(N+1). We get
eN+11=1+N1−2N21+O(N−3).
Exercise 33
We can expand the number of terms for HN from Table 4.6. The first approximation to within O(1/N) is
Notice that O(x5) is a sharper remainder than O(x4); we should always seek tightest bounds. In the derivation, we have used the first 3 terms of the geometric series, instead of just two as in the example from the book.
The middle term in the penultimate line must be expanded as 1+x+x2/2, where x is the argument to the exponential function. We must retain the three asymptotically largest components.
Exercise 41
When interest is compounded daily at a 10% annual rate on a $10,000 principal, after 365 days, the amount is . Instead of computing this value directly, let’s apply the result from Exercise 39. Here, we have λ=−0.1, so the total amount increases to . This is about $51.8 more than what would be paid if interest were paid once a year.
The exact formula gives $51.6, which is $0.02 less than our quick calculation. This showcases the advantages of using asymptotic approximations.
For large N, using Stirling's approximation for N! and expansion of the geometric series, we get
N!1=2πN1(Ne)N(1−12N1+O(N21)).
Nonetheless, if we would substitute this into the sine function, then we would go down the rabbit hole. N!1 is already a rational function of N, hence we can directly use it in further expansions.
At this point, we could say that the order of growth of sin(tan(1/N))–tan(sin(1/N)) is O(N−5), but this would be a loose bound. Since the first two terms match, we must expand until we find a difference. Let x=1/N and leverage WolframAlpha to perform the hard work.
series sin(tan(x)) to order 7series tan(sin(x)) to order 7=x+61x3−401x5−100855x7+O(x9)=x+61x3−401x5−5040107x7+O(x9).
Apparently, we have a mismatch at the 4th term, thus the order of growth of sin(tan(1/N))–tan(sin(1/N)) is O(N−7).
Exercise 45
TNHN=πN34N(1+O(1/N))=lnN+γ+O(1/N).
By substituting N=TN into the expansion of HN, we get
HTN=2Nln2−lnπN3+γ+O(1/N).
Exercise 46
This exercise is about the asymptotic expansion of the Lambert W function. The cited article contains the full expansion in terms of substitutions L1 and L2. We depict here the steps leading to the that expression using those symbols.
We derive the basic equation marked with an asterisk
nlnnan=anean=lnan+an=L1−lnan(*).
The first iteration of bootstrapping gives an≈L1. The second iteration gives an≈L1−L2. The third iteration gives
By carrying out one more iteration, we get the equation from the cited article to within the requested accuracy. For the sake of completeness, here is the identity without using symbols L1 and L2
We need to provide the reversion of the power series y = c0 + c1x + c2x2 + c3x3 + O(x4). By applying the hint from the book, this equation transform into z=x+c2′x2+c3′x3+O(x4). We already know the reversion of this form from the book:
x=z−c2′z2+(2c2′−c3′)z3+O(z4).
Now, we just need to express it again in terms of y and the original coefficients
In series reversion, the expansion for x is in powers of the small quantity y−c0, not y itself (unless c0=0). Therefore, the error term should be written as O((y−c0)4). Using O(y4) is incorrect when c0=0 because y doesn’t tend to zero.
Exercise 48
∑k≥11/k2=π2/6, which is known as the Basel problem. According to the direct comparison test, our sum ∑k≥11/(k2Hk) converges, too. The tail RN can be approximated using the asymptotic expansion of HN=lnN+δ (see Table 4.6), where δ>0 for large N. This gives
What’s the purpose of all this? Without our asymptotic estimate, if we wanted to find the value of C, we would just sum the first N terms. Because the original error is ≈NlnN1, the series converges excruciatingly slowly. But now we can rearrange the equation to compute C differently
C=k=1∑Nk2Hk1+NlnN1+O(N(logN)21).
The new error rate drops much faster, so we save both time and increase accuracy. In spirit, this technique of boosting numerical computations is known as Richardson extrapolation. There are many other similar methods to speed up convergence of series.