-3

n is a number between 1 and +infinity and this is to know the complexity of an algorithm I need to see if n^log(n) is bigger than n!

Simulant
  • 19,190
  • 8
  • 63
  • 98
  • And what exact is your problem? Just by trieing some examples you could see, that n! will be much bigger. n! will multiply each number till n (n=4: 1*2*3*4 = 24) where log(n) is much smaller then n (have a look at a graph). (n=4: log(4) ~ 0.6; 4^0.6 = 2.3) – Jarlik Stepsto Jan 12 '21 at 09:00

1 Answers1

0

If I understand your question correctly, you are asking whether n^(log n) is, in the limit where n goes to infinity, larger than n!. The short answer is no: in this limit, n! is (much) larger than n^(log n).

This can be proved using Stirling's approximation (see for instance https://en.wikipedia.org/wiki/Stirling%27s_approximation), according to which log(n!) is equivalent (up to a prefactor depending on the log base) to n log(n). By comparison, log(n^(log(n))) is equal to log(n)². Since n > log(n) for all positive integers, this gives log(n!) > log(n^(log(n))) for large values of n, and thus n! > n^(log(n)).

(More formally, this means that any function of n which is O(n^(log(n))) is also O(n!), although the converse is not true. If you are interested, you may find more details in the Wikipedia article on the big-O notation (https://en.wikipedia.org/wiki/Big_O_notation) or these lecture notes: https://web.mit.edu/16.070/www/lecture/big_o.pdf.)

Here is a plot illustrating this (I chose a logarithmic scale for the vertical axis as n! becomes quite large for even moderately large values of n):

Plot of n^(log(n)) and n! for n from 1 to 100

As you can see, for large values of n, n! is much larger than n^(log n). Here is the Python code I used for generating the plot:

import numpy as np
import matplotlib.pyplot as plt

# maximum value of n
max_n = 100

list_n = range(1, max_n+1)

# array of values of n^(log(n))
# NumPy uses a base-e log
n_exp_log_n = [n**(np.log(n)) for n in list_n]

# array of values of n!
factorial_n = [np.math.factorial(n) for n in list_n]

# plot the results with logarithmic vertical scale
plt.plot(list_n, n_exp_log_n, label='$n^{\log (n)}$')
plt.plot(list_n, factorial_n, label='$n!$')
plt.xlim(1, max_n)
plt.xlabel('$n$')
plt.yscale('log')
plt.legend()
plt.grid()
plt.tight_layout()
plt.show()

If your question is whether n^(log(n)) > n! is true for some positive integer, the answer is also no: they are equal for n = 1 and n! > n^(log(n)) for n > 1. (The formal proof is not difficult, but requires a bit more algebra.)