I have a piece of code which executes three nested for loops in the following way (written as language agnostic as possible):
for i = 0 to n - 1
for j = 0 to n - 1
for k = 0 to n - 1
[do computation in linear time]
My intuition says that this should result in N^3 complexity. I'd like to compare its complexity to the following nested loops:
for i = 0 to n - 1
for j = i + 1 to n - 1
for k = j + 1 to n - 1
[do computation in linear time]
Logically, it should be faster, because as i
increases, the inner loops should compute faster; however, having seen countless other threads on the site explaining that the latter of those is also N^3 is confusing.
Is my assumption of N^3 for both correct, and if so, how do I quantify the differences, assuming there are any?