for(int i = 0; i < 1; i++)
for(int j = 0; j < 1; j++)
a = i;
what is the big O of this fragment code.
i said it will be O(n2), but my teacher said it is O(n)
for(int i = 0; i < n*n; i++)
for(int j = 0; j <= i; j++)
a = i;
and for this one i said it is O(n3), but my teacher said it is O(n2)
is there any one who can help me understand that i am wrong, i can't admit it.
I just did it in an assumption that all arithmetic and logical operations will be computed once and for each nested loop there will be an extra n. Thanks in advance.

New Topic/Question
Reply



MultiQuote








|