Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(log(n))^log(n) and n/log(n), which is faster?

f(n)=(log(n))^log(n)

g(n)= n/log(n)

f = O(g(n))?

like image 923
Soup Avatar asked Dec 07 '22 03:12

Soup


2 Answers

Take the log of both sides:

log(f(n)) = log(log n) * log n

log(g(n)) = log(n) - log(log(n)) = log(n)(1 - log(log(n))/log(n))

Clearly log(log(n)) dominates (1 - log(log(n))/log(n)), so g is O(f). f is not O(g). Since it's homework, you may need to fill in the details.

It's also fairly easily to get an idea what the answer should be just by trying it with a large number. 1024 is 2^10, so taking n=1024:

f(n) = 10^10

g(n) = 1024/10.

Obviously that's not a proof, but I think we can see who's winning this race.

like image 53
Steve Jessop Avatar answered Jan 01 '23 21:01

Steve Jessop


f(n) grows faster than g(n) if and only if f(en) also grows faster than g(en) since exp is strictly increasing to infinity (prove it yourself).

Now f(en) = nn and g(en) = en / n, and you can quote the known results.

like image 29
kennytm Avatar answered Jan 01 '23 20:01

kennytm