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
List the functions below from the lowest to the highest order. If any two or more are of the same order, indicate which.
n π π n ( n 5 ) 2 n ( n n − 4 ) 2 log 4 n n 5 ( log n ) 2 n 4 ( n n − 4 ) \begin{matrix} n^\pi &\pi^n &\binom{n}{5} &\sqrt{2^{\sqrt{n}}}\\ \binom{n}{n-4} &2^{\log^4n} &n^{5(\log{n})^2} &n^4\binom{n}{n-4} \end{matrix} n π ( n − 4 n ) π n 2 l o g 4 n ( 5 n ) n 5 ( l o g n ) 2 2 n n 4 ( n − 4 n ) [1] First, the order of the sequence whose components' order is dominated by a power of a read number is simply the same as the order of their exponent. And, an expansion of binomial statement produces polynomial.
Think of expanding binomals:
( n 5 ) = 1 5 ! n ( n − 1 ) ( n − 2 ) ( n − 3 ) ( n − 4 ) = Θ ( n 5 ) ( n n − 4 ) = n ! ( n − 4 ) ! 4 ! = Θ ( n 4 ) n 4 ( n n − 4 ) = n 4 ∗ Θ ( n 4 ) = Θ ( n 8 ) \begin{align} \binom{n}{5}&=\frac{1}{5!}n(n-1)(n-2)(n-3)(n-4)\\ &=\Theta(n^5)\\\\ \binom{n}{n-4}&=\frac{n!}{(n-4)!4!}\\ &=\Theta(n^4)\\\\ n^4\binom{n}{n-4}&=n^4*\Theta(n^4)\\ &=\Theta(n^8) \end{align} ( 5 n ) ( n − 4 n ) n 4 ( n − 4 n ) = 5 ! 1 n ( n − 1 ) ( n − 2 ) ( n − 3 ) ( n − 4 ) = Θ ( n 5 ) = ( n − 4 )! 4 ! n ! = Θ ( n 4 ) = n 4 ∗ Θ ( n 4 ) = Θ ( n 8 ) So, the order of them, plus n π n^\pi n π (3 < π < 4 3 \lt \pi \lt 4 3 < π < 4 ), is:
n π < ( n n − 4 ) < ( n 5 ) < n 4 ( n n − 4 ) \begin{equation} n^\pi \lt \binom{n}{n-4} \lt \binom{n}{5} \lt n^4\binom{n}{n-4} \end{equation} n π < ( n − 4 n ) < ( 5 n ) < n 4 ( n − 4 n ) [2] Make the 4th statement easy:
2 n = ( 2 n 1 2 ) 1 2 = 2 n 1 2 2 \begin{align} \sqrt{2^{\sqrt{n}}}&=(2^{n^\frac{1}{2}})^{\frac{1}{2}}\\ &=2^{\frac{n^{\frac{1}{2}}}{2}} \end{align} 2 n = ( 2 n 2 1 ) 2 1 = 2 2 n 2 1 So the form belongs to more generic form:
2 n ∈ { x : x = 2 a n b ( a , b ∈ R ) } \begin{equation} \sqrt{2^{\sqrt{n}}}\in\{x:x=2^{an^b} (a,b\in\mathbb{R})\} \end{equation} 2 n ∈ { x : x = 2 a n b ( a , b ∈ R )} [3] Think of 2 log 4 n 2^{\log^4n} 2 l o g 4 n and its range.
Is n^b dominate log^4n?
lim n → ∞ log 4 n n b = lim x → ∞ ( ( log n ) ∗ 1 n b 4 ) 4 = lim n → ∞ ( ( log ( n 4 b ) 1 4 b ) ∗ 1 n b 4 ) 4 = lim n → ∞ 1 ( 4 b ) 4 log ( n b ) 1 n b \begin{align} \lim\limits_{n \to \infty}{\frac{\log^4n}{n^b}}&=\lim\limits_{x \to \infty}((\log{n})*\frac{1}{n^{\frac{b}{4}}})^4\\ &=\lim\limits_{n \to \infty}((\log{(n^{4b})^{\frac{1}{4b}}})*\frac{1}{n^{\frac{b}{4}}})^4\\ &=\lim\limits_{n \to \infty}\frac{1}{(4b)^4}\log{(n^b)^\frac{1}{n^b}} \end{align} n → ∞ lim n b log 4 n = x → ∞ lim (( log n ) ∗ n 4 b 1 ) 4 = n → ∞ lim (( log ( n 4 b ) 4 b 1 ) ∗ n 4 b 1 ) 4 = n → ∞ lim ( 4 b ) 4 1 log ( n b ) n b 1 Here we use following well known relationship:
lim m → ∞ m 1 m = 1 \begin{equation} \lim\limits_{m \to \infty}m^{\frac{1}{m}}=1 \end{equation} m → ∞ lim m m 1 = 1 And lim n → ∞ log 4 n n b \lim\limits_{n \to \infty}{\frac{\log^4n}{n^b}} n → ∞ lim n b l o g 4 n converges:
lim n → ∞ log 4 n n b = lim n → ∞ 1 ( 4 b ) 4 log 1 = 0 \begin{align} \lim\limits_{n \to \infty}{\frac{\log^4n}{n^b}}&=\lim\limits_{n \to \infty}\frac{1}{(4b)^4}\log{1}\\ &=0 \end{align} n → ∞ lim n b log 4 n = n → ∞ lim ( 4 b ) 4 1 log 1 = 0 Therefore, n b n^b n b dominate log 4 n \log^4n log 4 n .
Meanwhile, for sufficiently large n, log 4 n \log^4n log 4 n dominates log n \log{n} log n .
So, for sufficiently large n, the following relations hold:
a 1 log n < log 4 n < a 2 n b ⟺ n a 1 < 2 log 4 n < 2 a 2 n b ( a 1 , a 2 , b ∈ R ) \begin{align} &a_1\log{n}\lt\log^4n\lt a_2n^b\\ \iff &n^{a_1}\lt 2^{\log^4n} \lt 2^{a_2n^b} \quad(a_1,a_2,b\in\mathbb{R}) \end{align} ⟺ a 1 log n < log 4 n < a 2 n b n a 1 < 2 l o g 4 n < 2 a 2 n b ( a 1 , a 2 , b ∈ R ) Comparing the result of [2], we get the following:
2 log 4 n < 2 n \begin{equation} 2^{\log^4n} \lt \sqrt{2^{\sqrt{n}}} \end{equation} 2 l o g 4 n < 2 n [4] Think of n 5 ( log n ) 2 n^{5(\log{n})^2} n 5 ( l o g n ) 2 and its range.
First, set the value as m and take the log of n for both sides.
m = n 5 ( log n ) 2 ⟺ log n m = 5 ( log n ) 2 \begin{align} &m=n^{5(\log{n})^2}\\ \iff &\log_n{m}=5(\log{n})^2 \end{align} ⟺ m = n 5 ( l o g n ) 2 log n m = 5 ( log n ) 2 LHS can be rearranged:
log n m = 1 log n ∗ lg 10 lg m \begin{equation} \log_n{m}=\frac{1}{\log{n}*\lg10}\lg{m} \end{equation} log n m = log n ∗ lg 10 1 lg m So, combine the results above:
lg m = 5 lg 10 ( log n ) 3 ⟺ m = 2 5 lg 10 ( log n ) 3 \begin{align} &\lg{m}=5\lg10(\log{n})^3\\ \iff& m=2^{5\lg10(\log{n})^3} \end{align} ⟺ lg m = 5 lg 10 ( log n ) 3 m = 2 5 l g 10 ( l o g n ) 3 ( log n ) 4 (\log{n})^4 ( log n ) 4 dominates ( log n ) 3 (\log{n})^3 ( log n ) 3 , and ( log n ) 3 (\log{n})^3 ( log n ) 3 dominates log n \log{n} log n . So, n 5 ( log n ) 2 n^{5(\log{n})^2} n 5 ( l o g n ) 2 can be integrated in [3]'s result:
n a < n 5 ( log n ) 2 < 2 log 4 n < 2 n ( a ∈ R ) \begin{equation} n^{a}\lt n^{5(\log{n})^2} \lt 2^{\log^4n} \lt \sqrt{2^{\sqrt{n}}} \quad(a\in\mathbb{R}) \end{equation} n a < n 5 ( l o g n ) 2 < 2 l o g 4 n < 2 n ( a ∈ R ) [5] For sufficiently large n n n , π n \pi^n π n is larger than 3 n 3^n 3 n , and 3 n 3^n 3 n is larger than 2 n 2^n 2 n . so,
2 n < π n \begin{equation} \sqrt{2^{\sqrt{n}}} \lt \pi^n \end{equation} 2 n < π n Using [1] to [5], the order we want is:
n π < ( n n − 4 ) < ( n 5 ) < n 4 ( n n − 4 ) < n 5 ( log n ) 2 < 2 log 4 n < 2 n < π n ( the answer ) \begin{align} &n^\pi \lt \binom{n}{n-4} \lt \binom{n}{5} \lt n^4\binom{n}{n-4} \\ \lt &n^{5(\log{n})^2} \lt 2^{\log^4n} \lt \sqrt{2^{\sqrt{n}}} \lt \pi^n \quad(\text{the answer}) \end{align} < n π < ( n − 4 n ) < ( 5 n ) < n 4 ( n − 4 n ) n 5 ( l o g n ) 2 < 2 l o g 4 n < 2 n < π n ( the answer )