Which algorithm is more efficient?

71 Views Asked by At

Which algorithm is more efficient. Is it a or b?

a. $O(n^{2.81})$

b. $O((n^3 )/ \ln n)$

I want to solve this problem using l'Hospital's rule, $\lim(f(n)/g(n)) = \lim(f'(n)/g'(n))$

L'Hospital's Rule (1696): If $f(n)$ and $g(n)$ are both differentiable with derivatives $f'(n)$ and $g'(n)$, respectively, and if $\lim f(n) = \lim g(n) = \infty$, then $\lim \frac{f(n)}{g(n)} = \lim \frac{f'(n)}{g'(n)}$, whenever the limit on the right exists.

Example (1) $f(n) = n^3$ and $g(n) = \ln n$? $f'(n)=3n^2$ and $g'(n)=1/n$ so $\lim \frac{n^3}{\ln n}=\lim \frac{3n^2}{1/n}=\infty$. therefore, $g(n)$ is more efficient than $f(n)$.

2

There are 2 best solutions below

0
On

$$\lim_{n\to\infty} \frac{(\frac{n^3}{\ln{n}})}{n^{2.81}}=\lim_{n\to\infty} \frac{n^{0.19}}{\ln{n}}=\lim_{n\to\infty} \frac{0.19\cdot n^{-0.81}}{n^{-1}}=\lim_{n\to\infty} 0.19\cdot n^{0.19}=\infty$$ So the more efficient algorithm is the one which is $O(n^{2.81})$ as $O(\frac{n^3}{\ln{n}})$ has an infinitely greater complexity.

1
On

L'Hospital's rule is for quotient of functions with limit $0$. Here all you have to do is divide and simplify : $$\frac{n^{2.81}}{\frac{n^3}{\ln n}} = n^{2.81}\frac{\ln n}{n^3} = \frac{\ln n}{n^{0.19}} \xrightarrow[n\to\infty]{} 0$$ so $O\left(n^{2.81}\right)$ is more efficient than $O\left(\frac{n^3}{\ln n}\right)$.