-1

Hi I know two nested for loops will have time Complexity of O(n²). However let's say first loop starts from 0 and goes upto variable X max value(suppose x is n) and second loop starts from +1 of the first loop then we woudn't compare all the values of x with all the other values of x.In that case it woudn't be n². In that case +1 method cannot be O(n²) right? So what is it? Thanks.

lemikistu
  • 3
  • 2

1 Answers1

0

In this example, you will do on total n x (n/2) = n²/2 iterations. This is better than n² of course... But still O(n²).

If you double n, the number of iterations growth by a factor 4.

Optidad
  • 1,778
  • 1
  • 9
  • 12