3 ms·
For those who missed it, the absence of "n" in these loops makes "do something" happen a constant number of times. So as written by the OP the loops are current
by gridspy 8y ago
For those who missed it, the absence of "n" in these loops makes "do something" happen a constant number of times. So as written by the OP the loops are currently O(1)
if for (int i = 0; i < 1000; i++) were instead
for (int i = 0; i < n; i++) - You'd have O(n)
If also for (int j = 1000; j >= 1; j = j / 2) were instead
for (int j = n; j >= 1; j = j / 2) - Then you'd have O(n log n)
OR for (int j = n; j >= 1; j -= 1) - O(n^2)
OR for (int j = n * 1000; j >= 1; j -= 1) - this is STILL O(n^2)