Complexity of algorithm -
Complexity of algorithm -
what complexity given next problem o(n). shouldn't o(n^2)? because outer loop o(n) , inner o(n), hence n*n = o(n^2)?
the reply sheet of question states reply o(n). how possible?
public static void q1d(int n) { int count = 0; (int = 0; < n; i++) { count++; (int j = 0; j < n; j++) { count++; } } }
the complexity next problem o(n^2), how can obtain that? can please elaborate?
public static void q1e(int n) { int count = 0; (int = 0; < n; i++) { count++; (int j = 0; j < n/2; j++) { count++; } } }
thanks
the first illustration o(n^2)
, seems they've made mistake. calculate (informally) sec example, can n * (n/2) = (n^2)/2 = o(n^2)
. if doesn't create sense, need go , brush meaning of beingness o(n^k)
is.
algorithm
Comments
Post a Comment