TADM2E 2.8

From Algorithm Wiki
Revision as of 18:14, 11 September 2014 by Algowikiadmin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

2-8.

For each of the following pairs of functions, either <math>f(n)</math> is in <math>O(g(n))</math>, <math>f(n)</math> is in <math>\Omega(g(n))</math>, or <math>f(n)=\Theta(g(n))</math>. Determine which relationship is correct and briefly explain why.


<math>f(n)=\log n^2</math>; <math>g(n)=\log n</math> + <math>5</math>

Answer: <math>\log n^2 = \Theta (\log n + 5)</math>


Solution:

<math>\log n^2 = 2 \times \log n</math>

<math>2 \times \log n \le 2 \times \log n + 10</math>

<math>\log n^2 \le 2 (\log n + 5)</math>

<math>\log n^2 \le C (\log n + 5)</math> (where <math>C=2</math>)

<math>\log n^2 = O (\log n + 5)</math>

Also:

<math>\log n + 5 \le \log n + 5 \log n</math>

<math>\log n + 5 \le 6 \log n</math>

<math>\log n + 5 \le 3 \times 2 \log n</math>

<math>3 \times \log n^2 \ge \log n + 5 </math>

<math>\log n^2 \ge C \times (\log n + 5)</math> (Where <math>C =\frac{1}{3}</math>)

<math>log n^2 = \Omega (\log n + 5)</math>

And therefore:

<math>log n^2 = \Theta (\log n + 5)</math>


<math>f(n)=\sqrt{n}</math>; <math>g(n)=\log(n^2)</math>

Answer: <math>f(n) = \Omega(g(n))</math>


Solution:

<math>g(n) = \log (n^2) = 2 * \log (n)</math>

<math>\lim_{n \to \infty} \frac{\sqrt{n}}{2 * log(n)} = 2 * \lim_{n \to \infty} \frac{\sqrt{n}}{log(n)} = \infty</math>


<math>f(n)=\log^2(n)</math>; <math>g(n)=\log (n)</math>

Answer: <math>f(n) = \Omega(g(n))</math>


Solution:

<math>\lim_{n \to \infty} \frac{log^2(n)}{log(n)} = \lim_{n \to \infty} log(n) = \infty</math>


<math>f(n)=n</math>; <math>g(n)=\log^2(n)</math>

Answer: <math>f(n) = \Omega(g(n))</math>


Solution:

<math>\lim_{n \to \infty} \frac{n}{\log^2(n)} = \lim_{n \to \infty} ((\frac{\sqrt{n}}{\log(n)})^2) = (\lim_{n \to \infty} \frac{\sqrt{n}}{\log(n)})^2 = \infty</math>


<math>f(n)=n * \log(n) + n</math>; <math>g(n)=\log (n)</math>

Answer: <math>f(n) = \Omega(g(n))</math>


Solution:

<math>\lim_{n \to \infty} \frac{n * \log(n) + n}{log(n)} = \lim_{n \to \infty} (\frac{n * \log(n)}{log(n)} + \frac{n}{log(n)}) = \lim_{n \to \infty} (n + \frac{n}{log(n)}) = \infty</math>


<math>f(n)=10</math>; <math>g(n)=\log (10)</math>

Answer: <math>f(n) = \Theta(g(n))</math>


Solution: Both are constants. Constants are always within a constant factor, <math>c</math>, of each other (as <math>n \rightarrow \infty</math>).


<math>f(n)=2^n</math>; <math>g(n)=10n^2</math>

Answer: <math>f(n) = \Omega(g(n))</math>


Solution:

<math>\lim_{n \to \infty} \frac{2^n}{10n^2} = \frac{1}{10} (\lim_{n \to \infty} \frac{2^n}{n^2}) = \frac{1}{10} (\lim_{n \to \infty} \frac{n * 2^{n-1}}{2 * n})</math> <span style='padding-left:10px'>(L'Hopital's Rule)</span>

<math> = \frac{1}{10} (\lim_{n \to \infty} 2^{n-2}) = \infty </math>


<math>f(n)=2^n</math>; <math>g(n)=3^n</math>

Answer: <math>f(n) = O(g(n))</math>


Solution:

<math>\lim_{n \to \infty} \frac{2^n}{3^n} = \lim_{n \to \infty} (\frac{2}{3})^n = 0</math>