-1

I have a question if I have my $k=300$ and my loop is like this :

for( int x = 0 ; x<n ; x--){
    for(int y=0 ; y<k; y++){
        ...
    }
}

Is this still $O(n^2)$? If no, why? Thank you :)

Paresh
  • 3,368
  • 1
  • 21
  • 33
NilRad
  • 101
  • 1

1 Answers1

4

Assuming that you meant x++ rather than x--, the complexity is $\Theta(nk)$. Since $k = 300$, you can simplify that to $\Theta(n)$. As Ran G. mentions, since $n = O(n^2)$, then your loop is also $O(n^2)$. It's also $O(2^n)$. But the tight analysis is $\Theta(n)$.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514