2

Is O(N!N) an acceptable big oh complexity class or do I remove the constant and just say O(N!)?

2cs
  • 33
  • 4
  • 6
    That isn't a constant. – SLaks Nov 02 '18 at 01:14
  • So if it was O(N!+N) then the second N would be a constant? – 2cs Nov 02 '18 at 01:17
  • 2
    `O(n!*n)` is rather high complexity. But since there is multiplication you cannot remove second n. But if there was addiction like `o(n!+n)` then n could be omitted since fir big values of n, `n` is not significant compared to `n!` – Ivan Nov 02 '18 at 02:00
  • Possible duplicate of [Big O, how do you calculate/approximate it?](https://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it) – Matt Nov 02 '18 at 02:12
  • @ivan that’s really an answer, not a comment; please consider converting it – Mike Dinescu Nov 03 '18 at 23:34

3 Answers3

2

See What is O(log(n!)) and O(n!) and Stirling Approximation, which discusses the relationship between O(n!) and O(n^n). This should help you to determine the appropriate big-O when you multiply those by n.

The additional n in your problem is not a constant, and is not dominated by the n!, so it does not disappear from the function when you convert from the actual value of the function to the Big-O (or Big-Theta) asymptotic complexity class of the function.

For Big-O, it's probably sufficient to say O(n^(n+1)), but that's not sufficient for Big-Theta.

Here's a related problem involving Big-O and factorials: https://math.stackexchange.com/questions/323290/stirlings-approximation

Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
2

Lets do some algebra ....

  N!      =  N x (N - 1) x (N - 2) x ... 1    // by definition

  N! x N  =  N x (N x (N - 1) x (N - 2) x ... 1)

          =  (N + 1 - 1) x (N x (N - 1) x (N - 2) x ... 1)

          =  ((N + 1) x N x (N - 1) x (N - 2) x ... 1) 
              - (N x (N - 1) x (N - 2) x ... 1)

          =  (N + 1)! - N!

Now, it is "intuitively obvious"1 that O((N + 1)! - N!) is the same as O((N+1)!) ... and this can be proved from first principles.

Also, it is "intuitively obvious" that O(N!N) is N times as expensive as O(N!) which puts it into a different complexity class. (Just like O(N) and O(N^2) are different complexity classes!)


But here's the thing. The O(N!) complexity class is clearly problematic for practical computations as N gets large. It is substantially worse than simple exponential.

  N!   ~=  N^N for large N  // by Stirling's Approximation

  N^N   =  e^(NlogN)

  e^(NlogN) >> e^N for large N

So basically, whether you have O(N!) or O(N!N) you have a big problem ... either way.


1 - Statements like "intuitively obvious" are not proper maths. Obviously.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

O(n!*n) is rather high complexity. But since there is multiplication you cannot remove second n. But if there was addiction like o(n!+n) then n could be omitted since for big values of n, n is not significant compared to n!

Ivan
  • 8,508
  • 2
  • 19
  • 30
  • To extend the answer: *not significant* - `n! + n < n! + n! = 2n!` take constant `c = 2`, same equivalence class. – Zabuzard Nov 04 '18 at 01:41