I am trying to understand the example for big O on this page: http://pages.cs.wisc.edu/~vernon/cs367/notes/3.COMPLEXITY.html
for (i = 0; i < N; i++) {
for (j = i+1; j < N; j++) {
sequence of statements }
}
I don't understand why inner loop will run for N if i=0. If i=0, then j=1, and as the result, number of iterations for inner loop should be N-1. I understand why the complexity of this loop is O(n^2). What I don't understand is why the inner loop starts with N number of iterations, not N-1.
Your link has a slight error. Indeed the inner loop starts from N-1 iterations rather than N, but the result remains the same.
Starting from that first mistake they miss 1 on each iteration. They forgot the +1 the j=i+1 I guess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With