0

I'm filling a lower triangular matrix like this:

for (i = 0; i < size; i++) {
    for (j = 0; j <= i; j++)
        l[i][j] = j + 1;
}

And I want to calculate the order of the code in Big O notation but I'm really bad. If it was a regular matrix it would be O(n²) but in this case I'm not sure if it's O(nlog(n)) or something like that.

1 Answers1

1

Typically (but not always) one loop nested in another will cause O(N²).

Think about it, the inner loop is executed i times, for each value of j. The outer loop is executed size times.

This comes out to be 1/2 of N^2, which is still O(N^2)

Lakshitha Wisumperuma
  • 1,574
  • 1
  • 10
  • 17