1.0 - Formal Definition of Asymptotic Bounds

1.1 - Upper Bounds

🌱 O(g)O(g) is the set of all functions that (1) have (exist) constants c,n0>0c, n_0 > 0 that is greater than or equal to f(n)f(n) for all nβ‰₯n0n \ge n_0.

O(g)={fβˆ£βˆƒc,n0>0βˆ™βˆ€nβ‰₯n0βˆ™0≀f(n)≀cβ‹…g(n)} O(g)=\{f | \exists c, n_0\gt 0 \bullet \forall n\ge n_0 \bullet 0 \le f(n) \le c\cdot g(n) \}


Using the formal definition above, prove that 2n3∈O(n3)2n^3\in O(n^3)


Using the formal definition above, prove that 2n2∈O(n3βˆ’n2)2n^2 \in O(n^3-n^2)

1.2 - Lower Bounds

🌱 Ξ©(g)\Omega(g) is the set of all functions that (1) have (exist) constants c,n0>0c, n_0 > 0 that is less than or equal to cβ‹…g(n)c\cdot g(n) for all nβ‰₯n0n \ge n_0.

Ξ©(g)={fβˆ£βˆƒc,n0>0βˆ™βˆ€nβ‰₯n0βˆ™,0≀cβ‹…g(n)≀f(n)} \Omega(g)=\{f|\exists c, n_0> 0\bullet \forall n\ge n_0 \bullet, 0 \le c\cdot g(n)\le f(n) \}


Using the above definition, prove that 2n3∈Ω(n3)2n^3\in \Omega(n^3)

1.3 - Tight Bounds

🌱 Θ(g)\Theta(g) is the set of all functions that (1) have (exist) constants c1,c2,n0>0c_1, c_2, n_0>0 that bounds the function f(n)f(n) on the top and bottom to within a constant factor.

Θ(g)={fβˆ£βˆƒc1,c2,n0>0βˆ™βˆ€nβ‰₯n0βˆ™0≀c1β‹…g(n)≀f(n)≀c2β‹…g(n)} \Theta(g)=\{f | \exists c_1, c_2, n_0 > 0\bullet \forall n\ge n_0 \bullet 0\le c_1\cdot g(n) \le f(n)\le c_2\cdot g(n)\}


Using the above definition, prove that 2n3∈Θ(n3)2n^3\in\Theta (n^3)


Using the above definition, prove that n22∈Θ(n2)\frac{n^2}2\in\Theta(n^2)


Using the above definition, prove that n22βˆ’2n∈Θ(n2)\frac{n^2}2 -2n\in \Theta(n^2)

1.4 - Properties of Asymptotic Notation

🌱 Theorem:

f∈O(g)⟹g+f∈Θ(g) f\in O(g)\Longrightarrow g+f\in \Theta(g)

For example, n∈O(n2)⟹n2+n∈Θ(n2)n\in O(n^2)\Longrightarrow n^2+n\in\Theta(n^2)

🌱 Theorem: For k>0k>0

kβ‹…na∈Θ(na) k\cdot n^a\in \Theta(n^a)

🌱 Theorem: For k>0k>0 and 0≀a≀b0\le a\le b

kβ‹…na∈O(nb) k\cdot n^a\in O(n^b)

🌱 Theorem: For any functions ff and gg

f∈O(g)⟺g∈Ω(f) f\in O(g)\Longleftrightarrow g\in\Omega(f)

🌱 Theorem: For any functions ff and gg

f∈Θ(g)⟺f∈O(g)∧f∈Ω(g) f\in\Theta(g)\Longleftrightarrow f\in O(g)\wedge f\in\Omega (g)

2.0 - Comparing Functions

🌱 A function ff is asymptotically non-negative if:

βˆƒn0βˆ™(βˆ€nβ‰₯n0βˆ™f(n)β‰₯0) \exists n_0\bullet (\forall n \ge n_0 \bullet f(n)\ge 0)

🌱 If ff and gg are asymptotically non-negative functions, and

lim⁑nβ†’βˆžf(n)g(n)=cβ‰₯0Β thenΒ f∈O(g)=c>0Β thenΒ f∈Θ(g)=∞ thenΒ g∈O(f) \begin{aligned} \lim_{n\rightarrow\infty} \frac{f(n)}{g(n)}&=c\ge0 \text{ then } f\in O(g)\\ &=c>0 \text{ then } f\in\Theta(g)\\ &=\infty\text{ then } g\in O(f) \end{aligned}

where cc is a real-valued constant

Plot of f(n)=nf(n)=n (red) and g(n)=n1+sin⁑ng(n)=n^ {1+\sin n}

3.0 - Polynomials

p(n)=βˆ‘k=0daknk=a0n0+a1n1+β‹―+adnd p(n)=\sum^d_{k=0} a_k n^k=a_0n^0+a_1n^1+\cdots+a_dn^d

🌱 Theorem: If ad>0a_d>0,

p(n)∈Θ(nd)p(n)\in\Theta(n^d)

lim⁑nβ†’βˆžp(n)nd=lim⁑nβ†’βˆžβˆ‘k=0daknknd=lim⁑nβ†’βˆžadndnd+βˆ‘k=0dβˆ’1aknknd=lim⁑nβ†’βˆžad+βˆ‘k=0dβˆ’1akndβˆ’k=ad \small\begin{aligned} &\lim_{n\rightarrow\infty} \frac{p(n)}{n^d}\\ =& \lim_{n\rightarrow\infty} \sum^d_{k=0} \frac{a_k n^k}{n_d}\\ =& \lim_{n\rightarrow\infty} \frac{a_dn^d}{n^d} + \sum^{d-1}_{k=0} \frac{a_k n^k}{n^d}\\ =& \lim_{n\rightarrow\infty} a_d + \sum^{d-1}_{k=0}\frac{a_k}{n^{d-k}}\\ =& a_d \end{aligned}

🌱 For a>1a>1 and nβ‰₯0,n\ge0,

nd∈O(an) {\color{lightblue}n^d}\in O({\color{lightgreen}a^n})

lim⁑nβ†’βˆžndadlim⁑nβ†’βˆždndβˆ’1anln⁑alim⁑nβ†’βˆžd(dβˆ’1)ndβˆ’2an(ln⁑a)2Β Β Β Β Β Β Β Β Β Β Β ByΒ L’Hopital’slim⁑nβ†’βˆžd(dβˆ’1)(dβˆ’2)β‹―1n0an(ln⁑a)dlim⁑nβ†’βˆžd!an(ln⁑a)d \begin{aligned} &\lim_{n\rightarrow\infty} \frac{\color{lightblue}n^d}{\color{lightgreen}a^d}\\ &\lim_{n\rightarrow\infty} \frac{dn^{d-1}}{a^n \ln a}\\ &\lim_{n\rightarrow\infty} \frac{d(d-1)n^{d-2}}{a^n(\ln a)^2} \ \ \ \ \ \ \ \ \ \ \ \text{By L'Hopital's}\\ &\lim_{n\rightarrow\infty} \frac{d(d-1)(d-2)\cdots 1 n^0}{a^n(\ln a)^d}\\ &\lim_{n\rightarrow\infty} \frac{d!}{a^n (\ln a)^d} \end{aligned}

As d!d! and (ln⁑a)d(\ln a)^d are constants, and anβ†’βˆža^n\rightarrow\infty, the limit is 0. Therefore, this has a tight-o bound.

4.0 - Mathematical Background

4.1 - Finite Summations

🌱 Given a sequence ⟨a1,a2,⋯ ,an⟩\langle a_1, a_2, \cdots, a_n\rangle, the finite summation is given as:

βˆ‘k=1nak=a1+a2+β‹―+an(1) \sum^n_{k=1} a_k=a_1+a_2+\cdots+a_n\tag{1}

4.2 - Infinite Summations

🌱 The infinite summation a1+a2+β‹―a_1+a_2+\cdots is represented as the limit of a finite summation:

βˆ‘k=1∞=lim⁑nβ†’βˆžβˆ‘k=1nak(3) \sum^\infty_{k=1}=\lim_{n\rightarrow\infty} \sum^n_{k=1} a_k\tag{3}

4.3 - Linearity

βˆ‘k=1n(cak+bk)=cβˆ‘k=1nak+βˆ‘k=1nbk(4) \sum^n_{k=1} (ca_k+b_k)=c\sum^n_{k=1}a_k+\sum^n_{k=1} b_k \tag{4}

4.4 - Arithmetic Series

βˆ‘k=1nk=n(n+1)2(5) \sum^n_{k=1}k=\frac{n(n+1)}{2}\tag{5}

4.5 - Geometric Series

4.5.1 - Finite Geometric Series

βˆ‘k=0nxk=1+x+x2+x3+β‹―+xn=xn+1βˆ’1xβˆ’1Β Β Β Β Β Β forΒ xβ‰ 1(6) \begin{aligned} \sum^n_{k=0}x^k&=1+x+x^2+x^3+\cdots+x^n \tag{6}\\ &=\frac{x^{n+1}-1}{x-1} \ \ \ \ \ \ \text{for } x \ne 1 \end{aligned}

4.5.2 - Infinite Geometric Series

βˆ‘k=0∞xk=11βˆ’xΒ Β Β Β Β Β Β for ∣x∣<1(7) \sum^\infty_{k=0}x^k=\frac{1}{1-x}\ \ \ \ \ \ \ \text{for } |x|<1\tag{7}

4.6 - Harmonic Series

Hn=1+12+13+β‹―+1n=βˆ‘k=1n1k(8) \begin{aligned} H_n&=1 + \frac{1}{2}+\frac13+\cdots+\frac1n &=\sum^n_{k=1} \frac1k \tag{8} \end{aligned}


Hn=ln⁑n+Ξ³β‡’Ξ³=0.577...H_n=\ln n + \gamma\Rightarrow \gamma=0.577...

4.7 - Tight Upper Bound

🌱 Little-o notation represents the tight asymptotic bound on a function.

o(g(n))={f(n):βˆ€c>0,βˆƒn0>0∣0≀f(n)<cβ‹…g(n),βˆ€nβ‰₯0} o(g(n))=\{f(n):\forall c >0, \exists n_0>0 | 0\le f(n)<c\cdot g(n), \forall n \ge 0\}

4.8 - L’Hopital’s Rule

🌱 How do you evaluate the limit lim⁑nβ†’βˆžf(n)g(n)\lim_{n\rightarrow\infty} \frac{f(n)}{g(n)} if it looks hard?

Consider lim⁑nβ†’af(n)g(n)\lim_{n\rightarrow a}\frac{f(n)}{g(n)} when either:

lim⁑nβ†’af(n)=0=lim⁑nβ†’ag(n) \lim_{n\rightarrow a} f(n)=0=\lim_{n\rightarrow a}g(n)

or when

lim⁑nβ†’af(n)=±∞=lim⁑nβ†’ag(n) \lim_{n\rightarrow a} f(n)=\pm\infty=\lim_{n\rightarrow a} g(n)

We can use L’Hopital’s rule, giving:

lim⁑nβ†’af(n)g(n)=lim⁑nβ†’addxf(n)ddxg(n)(10) \lim_{n\rightarrow a} \frac{f(n)}{g(n)}=\lim_{n\rightarrow a} \frac{\frac{d}{dx} f(n)}{\frac{d}{dx} g(n)}\tag{10}

4.9 - Telescoping Series

βˆ‘k=1n(akβˆ’akβˆ’1)=(a1βˆ’a0)+(a2βˆ’a1)+β‹―+(anβˆ’anβˆ’1)=anβˆ’a0(11) \begin{aligned} \sum^n_{k=1}(a_k-a_{k-1})&=(a_1-a_0) + (a_2-a_1)+\cdots+(a_n-a_{n-1})\\ &=a_n-a_0 \tag{11} \end{aligned}

βˆ‘k=0nβˆ’1(akβˆ’ak+1)=a0βˆ’an(12) \sum^{n-1}_{k=0}(a_k-a_{k+1})=a_0-a_n \tag{12}

Example:

βˆ‘k=1nβˆ’11k(k+1)=βˆ‘k=1nβˆ’1(1kβˆ’1k+1)=1βˆ’1n \sum^{n-1}_{k=1}\frac{1}{k(k+1)}=\sum^{n-1}_{k=1}(\frac1k-\frac1{k+1})=1-\frac1n

We know this because 1k(k+1)=1kβˆ’1k+1\frac1{k(k+1)}=\frac 1k-\frac 1{k+1}

4.10 - Differentiation

Example: βˆ‘k=0∞kxk\sum^\infty_{k=0} kx^k where ∣x∣<1|x|<1, we know:

βˆ‘k=0∞=11βˆ’xΒ Β Β Β Β if ∣x∣<1 \sum^\infty_{k=0}=\frac{1}{1-x}\ \ \ \ \ \text{if } |x|<1

Differentiation both sides with respect to xx gives:

βˆ‘k=0∞xk=1(1βˆ’x)2 \sum^\infty_{k=0} x^k = \frac{1}{(1-x)^2}

This gives:

βˆ‘k=0∞kxk=x(βˆ‘k=0∞kxkβˆ’1)=x(1βˆ’x)2 \sum^\infty_{k=0} kx^k=x(\sum^\infty_{k=0} kx^{k-1})=\frac{x}{(1-x)^2}

4.11 - Algebraic Manipulation

Example s=βˆ‘i=1∞i2is=\sum^\infty_{i=1} \frac{i}{2^i}

s=12+222+323+β‹―2s=1+22+322+β‹―2sβˆ’s=1+12+122+β‹―+=βˆ‘k=0∞12k=11βˆ’12=2 \begin{aligned} s&=\frac12+\frac{2}{2^2}+\frac{3}{2^3}+\cdots\\ 2s&=1+\frac22+\frac{3}{2^2}+\cdots\\ 2s-s&=1+\frac12+\frac{1}{2^2}+\cdots+\\ &=\sum^\infty_{k=0}\frac1{2^k}=\frac{1}{1-\frac{1}{2}}=2 \end{aligned}

so s=2s=2

4.12 - Products

Definitions:

∏k=1nak=a1a2β‹―an \prod^n_{k=1} a_k=a_1 a_2\cdots a_n

Note that by definition, products over empty ranges have a value of 1.

∏k=10ak=1 \prod^0_{k=1} a_k=1

Products can be converted to sums using logarithms

lg⁑∏k=1nak=βˆ‘k=1nlg⁑ak \lg \prod^n_{k=1}a_k=\sum^n_{k=1} \lg a_k

4.13 - Logarithms

Remember that log⁑x=log⁑2x\log x=\log_2x and ln⁑x=log⁑ex\ln x=\log_e x

4.14 - Bounding Sums - Upper Bounds

βˆ‘k=1nak≀namax \sum^n_{k=1} a_k\le na_{\text{max}}

For example:

βˆ‘k=1nkβ‰€βˆ‘k=1nn=n2 \sum^n_{k=1}k\le\sum^n_{k=1}n=n^2

If we know that ak+1ak≀r,βˆ€kβ‰₯0\frac{a_{k+1}}{a_k}\le r, \forall k \ge 0 with r<1r<1 as a constant (i.e. geometric series) then:

βˆ‘k=0nβ‰€βˆ‘k=0∞a0rk=a0βˆ‘k=0nrk≀a01βˆ’r \sum^n_{k=0}\le \sum^\infty_{k=0} a_0 r^k = a_0\sum^n_{k=0} r^k\le \frac {a^0}{1-r}

4.14 - Bounding Sums - Lower Bounds

βˆ‘k=1nak≀namin \sum^n_{k=1} a_k\le na_{\text{min}}

For example:

βˆ‘k=1nkβ‰₯βˆ‘k=1n1=n \sum^n_{k=1} k \ge \sum^n_{k=1}1=n

This is a linear bound, which is poor - Split the sum

βˆ‘k=1nk=βˆ‘k=1n/2k+βˆ‘k=n2+1nkβ‰₯βˆ‘k=1n20+βˆ‘k=n2+1nn2β‰₯(n2)2=n24 \sum^n_{k=1}k=\sum^{n/2}_{k=1}k+\sum^n_{k=\frac n2+1}k\ge \sum^\frac n2_{k=1} 0+\sum^n_{k=\frac n2 + 1} \frac n2 \ge (\frac n2)^2=\frac{n^2}4

This is a quadratic bound - Θ(n2)\Theta(n^2)

4.15 - Bounding Products - Upper and Lower Bounds

Give an upper and lower bound for the product n!n!

n!=1Γ—2Γ—β‹―Γ—3Γ—(nβˆ’1)Γ—n=∏k=1nk n!=1\times 2\times \cdots \times 3\times (n-1)\times n=\prod^n_{k=1}k

An upper bound for this product is:

n!=∏k=1nkβ‰€βˆk=1nn=nn n!=\prod^n_{k=1}k\le\prod^n_{k=1}n=n^n

A (trivial) lower bound for this product is:

n!=∏k=1nkβ‰₯∏k=1n1=1 n!=\prod^n_{k=1}k\ge \prod^n_{k=1}1=1

A tight lower bound for this product is

n!=∏k=1n2kΓ—βˆk=n2+1nkβ‰₯∏k=1n21Γ—βˆk=n2+1nn2=(n2)n2 \begin{aligned} n!&=\prod^\frac n2_{k=1}k\times\prod^n_{k=\frac n2 + 1} k\\ &\ge \prod^\frac n2 _{k=1} 1 \times \prod ^n _{k=\frac n2 + 1} \frac n2 = (\frac n2)^ \frac n2 \end{aligned}

Note that Stirling’s approximation gives:

n!=2Ο€n(ne)n(1+Θ(1n)) n!=\sqrt{2\pi n} (\frac ne)^n (1+\Theta(\frac 1n))

4.16 - Splitting Sums is a Powerful Technique

Consider using the splitting sums technique to compute the upper bound of the harmonic series:

Consider Hn=βˆ‘k=1n1kH_n=\sum^n_{k=1} \frac 1k

Split the range into ⌊lg⁑nβŒ‹\lfloor \lg n\rfloor pieces, with each piece summing ≀1\le 1

(1)+(1/2+1/3)+(1/4+1/5+1/6+1/7)+β‹― (1)+(1/2+1/3)+(1/4+1/5+1/6+1/7)+\cdots

βˆ‘k=1n1kβ‰€βˆ‘i=0⌊lg⁑nβŒ‹(βˆ‘j=02iβˆ’112i+j)β‰€βˆ‘i=0⌊lg⁑nβŒ‹(βˆ‘j=02iβˆ’112i)β‰€βˆ‘i=0⌊lg⁑nβŒ‹1≀1+lg⁑n \sum^n_{k=1}\frac 1k\le\sum^{\lfloor \lg n\rfloor}_{i=0} (\sum^{2^i-1}_{j=0} \frac 1{2^i + j})\le\sum^{\lfloor \lg n\rfloor}_{i=0}(\sum^{2^i-1}_{j=0} \frac 1 {2^i})\le \sum^{\lfloor \lg n \rfloor}_{i=0} 1 \le 1 + \lg n

4.17 - Approximation by Integrals

Consider βˆ‘k=mnf(k)\sum^n_{k=m} f(k) where f(k)f(k) is monotonically increasing:

∫mβˆ’1nf(x)Β dxβ‰€βˆ‘k=mnf(k)β‰€βˆ«mn+1f(x)Β dx \int^n_{m-1} f(x)\ dx\le\sum^n_{k=m} f(k) \le \int^{n+1}_m f(x)\ dx

There is a similar proof for monotonically decreasing functions:

∫mn+1f(x)Β dxβ‰€βˆ‘k=mnf(k)β‰€βˆ«mβˆ’1nf(x)Β dx \int^{n+1}_m f(x)\ dx \le \sum^n_{k=m} f(k) \le \int^n_{m-1} f(x)\ dx

Thus Hnβ‰₯∫1n+11xdx=ln⁑(n+1)H_n\ge \int^{n+1}_1 \frac 1x dx = \ln (n + 1) and βˆ‘k=2n1kβ‰€βˆ«1n1xdx=ln⁑n\sum^n_{k=2} \frac 1k \le \int ^n_1 \frac 1x dx=\ln n so Hn≀ln⁑n+1H_n\le \ln n +1