i=1;
while(i<n*n)
i=i+n;
from my lecturer provided answer:
Big-O notation was O(n) instead O(n^2) why?
asked Sep 15, 2015 at 16:50
1 Answer 1
Because after each loop run n is added to i. So it has to run maximal n times to reach n2, thus ending the loop.
O(n^2) would be:
i=1;
while(i<n*n)
i=i+1;
answered Sep 15, 2015 at 17:17