algorithm - Time complexity of nested loop -
im trying find worst case time complexity next algorithm.
for (i = n*n; i>1; = /2 ){ ( j = 0; j < i; j++){ counter++; } }
i managed figure out inner loop execute in logarithmic fashion (backwards though, think doesnt matter) im unsure how approach outer loop.
as @clintpowell pointed out, inner loop o(i)
. trick, then, add together various values i
.
suppose outer loop i=1; i<=k; i=i*2
(as point out, order doesn't matter), , solve in terms of k
. substitute n*n
k
, , simplify necessary.
algorithm time-complexity
No comments:
Post a Comment