Big O, algorithm analysis
I'm wondering what is the big O notation for each of the below statement:
Sum = 0;
for i=1 to N^2 do:
for j=1 to N do:
'Sum += 1;
Sum = 0 is O(1) for sure, because it will only be executed once. But I'm
confused by the second statement, should it be O(N) because it's the first
loop? or it should be O(N^2) because N^2 is a quadratic function about
variable N?
No comments:
Post a Comment