0

From what I understand saying that if an algorithm is in Θ(log(n!)) then it is in O(n log(n)) is correct, as big-O denotes an upper bound. Would it be also correct to say that if an algorithm is in Θ(log(n!)) then it is in Θ(n log(n))?

By plotting the two growths I can see they are similar but is it correct to say that they are equivalent?

1 Answers1

1

Yes. n! < nn, so log(n!) < n * log(n).

At the same time, n! > (n/2)n/2 (for even n), so log(n!) > (n/2) * (log(n)-1)

Matt Timmermans
  • 36,921
  • 2
  • 27
  • 59
  • I'm sorry if the question wasn't clear. I know that log(n!) < n log(n), as I stated in the question body. I was asking if Θ(log(n!)) = Θ(n log(n)). –  Feb 18 '20 at 02:33
  • The question was very clear. The first line shows that O(n!) <= O(n log n). The second line shows that O(n log n) <= O(n!) – Matt Timmermans Feb 18 '20 at 02:34
  • Why does plotting the two show that log(n!) < n log(n) for every n? Is that irrelevant when referring to big-Theta notation? –  Feb 18 '20 at 02:40
  • It's relevant to the first part. You could also plot log(n!) and (n log (n))/3, which would go the other way for all sufficiently large n. They are the same up to multiplication by a constant, which is what you asked. – Matt Timmermans Feb 18 '20 at 02:42