0
$\begingroup$

For the computation of the log factorial, i.e., $\log(n!)$, is the Big(O) run time for this $n\log(n)$? How can this be assumed graphically?

***Update: How does the sum of $\log(n!)$ work then? I.e., the sum of log Factorial?

  • 0
    The sum comes from log rules. See my answer below.2017-02-20
  • 0
    I see the properties of the log rule, but is sum(log(n!)) then O(n *log(n)) as well??2017-02-20
  • 0
    No. Note that $$\log(n!)=\sum_{k=1}^n\log(k)=\mathcal O(n\log(n))$$2017-02-20
  • 0
    I added the graphical part. :D2017-02-20

2 Answers 2

3

Notice that:

$$\log(ab)=\log(a)+\log(b)$$

Thus,

$$\log(n!)=\sum_{k=1}^n\log(k)<\sum_{k=1}^n\log(n)=n\log(n)$$

A lower bound may be done with Riemann sums:

$$\sum_{k=1}^n\log(k)>\int_1^n\log(x)\ dx=n\log(n)-n+1$$

Here's the graphical component:

enter image description here

0

$$\log(n!) = \sum_{k=1}^n \log(k)$$ Can you figure it out from here using properties of Big-$O$ notation? You'll find that the answer to your conjecture is a resounding yes; graphically, this is because $n^n$ is a decent estimator of $n! $. Look up Stirling Approximation for more detail

  • 0
    Yes I can. Specifically, is the run time of the log(n!) nlog(n) in bigO?2017-02-20
  • 0
    @NinaMcGyver yes. Notice that $\lim_{n \to \infty} \frac{\log(n!)}{n\log(n)} = 1$2017-02-20
  • 0
    @NinaMcGyver graphically this is because $n^n$ is a decent estimator of $n! $. Look up Stirling Approximation for more detail2017-02-20
  • 0
    made an update above. Thanks2017-02-20
  • 0
    @BrevanEllefsen Isn't Stirling approximation overkill for this?2017-02-20
  • 0
    @SimplyBeautifulArt yes... but just take the simplest form of it and you're fine. Knowing the exact constants isn't important. This is more or less what you do in your post.2017-02-20
  • 0
    @SimplyBeautifulArt even your answer is overkill if you can take limits and already have the OP's conjecture for the record, as I point out in my comment above2017-02-20
  • 0
    Hm, now that I think about it, I feel like there should be different names to the approximations of the factorial. Who's idea was it to name them all "Stirling's approximation"?2017-02-20
  • 0
    @BrevanEllefsen :-/ Those limits aren't trivial though.2017-02-20
  • 0
    @BrevanEllefsen $n^n$ is not a decent estimator of $n!$. Actually, we have $n! \in o(n^n)$.2017-02-20