0

I want to prove that, $$ \log n! \in O(n \log n) \land \log n! \in \Omega(n \log n)$$ The straightforward approach is to apply Stirling's formula but I am looking for a different path to follow.

Can somebody please guide me towards it?

John L.
  • 38,985
  • 4
  • 33
  • 90

5 Answers5

3

Note that $\log n! = \sum_{k = 1}^n \log k$. Then $$\sum_{k = 1}^n \log k = \int_1^{n + 1} \log \lfloor x \rfloor dx \le \int_1^{n + 1} \log x dx = (n + 1) \log (n + 1) - n,$$ and $$\sum_{k = 1}^n \log k = \int_0^{n} \log \lceil x \rceil dx \ge \int_0^{n} \log x dx = n \log n - n .$$

hidanom
  • 83
  • 5
2

A nice method is : $$ \begin{align*} \log n! & = \log \prod_{\psi=1}^n \psi \\ & = \sum_{\psi=1}^n \log \psi \\ & \sim \int_1^n \log \psi \; \mathrm d \psi \\ & = \psi \log \psi - \psi \Biggr|_{1}^{n} \\ & = n \log n - (n - 1) \end{align*} $$ If we had used stirling's approximation instead, we would have received $$ \log n! = n \log n - n + \Theta(\log n) $$ Alternate methods involve

  • The method present in this math.se page.
  • Using $n! = \int_0^\infty x^n e^{-x} \; \mathrm d x$
axr
  • 296
  • 1
  • 6
  • 1
    Thanks for your answer, your use of $\psi$ is intimidating. – prideandprejudice Jun 15 '22 at 18:03
  • The step from the sum to the integral needs to be justified. Because it could turn out that the "quantization error" modifies the asymptotic behavior. –  Jun 16 '22 at 07:04
2

As far as I see, the solutions have all used integration. We can easily do without. Of course $\log n! = \sum_{k=1}^n \log k$.

For the upper bound use $\log k \le \log n$ for $1\le k \le n$, so $\sum_{k=1}^n \log k \le \sum_{k=1}^n \log n =n \log n$.

For the lower bound, observe that $\log \frac n2 \ge \frac 12{\log n}$ for $n\ge 4$. Thus $\sum_{k=1}^n \log k \ge \sum_{k={\frac n2}}^{n} \log k \ge \frac n2 \log \frac n2 \ge \frac n4 \log n$.

Hendrik Jan
  • 30,578
  • 1
  • 51
  • 105
  • 1
    This simple "trick" of lower bounding a sum by only some of its terms (usually half, not always) is enough to give the asymptotic behaviour (up to a constant factor) of most sums one might encounter in beginner algorithms courses. – Tassle Jun 19 '22 at 13:17
1

For complete rigor,

$$x-1\le\lfloor x\rfloor\le x$$

so that by monotonicity of the logartihm

$$\log(x-1)\le\log\lfloor x\rfloor\le \log x.$$

Hence by integration from $2$ to $n+1$,

$$\int_1^n\log x\,dx\le\sum_{k=2}^n\log k\le\int_2^{n+1}\log x\,dx$$

and

$$n\log n-n+1\le\log n!\le(n+1)\log(n+1)-n+1-2\log2.$$

-1

Without any hard maths: log n! = log 1 + log 2 + log 3 + … + log n. We are adding n numbers, each at most log n, so the sum is at most n log n.

On the other hand, log ( sqrt (n)) = (log n) / 2, so all but sqrt(n) of the numbers we are adding are at least (log n) / 2, giving a lower bound. For n>= 4, sqrt(n) <= n/2 so we are adding at least n/2 numbers, each at least (log n) / 2, for a total of (n log n) / 4.

gnasher729
  • 29,996
  • 34
  • 54