-1

Does the time complexity of the following pseudo-algorithm simplify as $O(n^2 log(n)) = O(n^2)$?

SOME ALGORITHM

GET n
FOR (i=1; i<=n; i++) 
    {
        calculationOfN[i] // some polylogarithmic time calculation 

        FOR (j=1; j<=n; j++)
            {
                // some linear calculation
            }
        FOR (k=0; k<=n; k++) 
            {
                // some linear calculation
            }
    // some statement
    }
// some statement
Raphael
  • 73,212
  • 30
  • 182
  • 400
Jeff
  • 113
  • 1
  • 9

1 Answers1

3

Assuming your linear calculations are actually constant-time calculations, then yes, the final time complexity of the algorithm will be $O(n^2)$ (but not for the reason you seem to be indicating).

Your polylogarithmic time calculation (running in time $O(\log^{k}n)$) is run $n$ times (one for each $i$); each of your secondary $O(1)$ time computations is run $O(n^2)$ times (one for each $(i,j)$ pair and $(i,k)$ pair respectively). Altogether, this leads to a time complexity of $O(n\log^{k}n + n^2)$ (notably, not $O(n^2\log^{k}n)$). Since $n^2$ dominates $O(n\log^{k}n)$, this is $O(n^2)$.

jschnei
  • 424
  • 2
  • 5