0
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

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.