in Algorithms retagged by
492 views
0 votes
0 votes

What is the time complexity of the following code snippet? Assume x is a global variable and “statement” takes O(n) time?

in Algorithms retagged by
492 views

4 Comments

I think it should be O(logn)
0
0
but answer is 0(n).
0
0
please explain...
0
0
I think they arr taking RR is T(n) = T(n/2) + n.

TC = O(n).

But "statement" will always take O(n) because they did not explicitly mention the relation between T(n) and (n). so for every T(n/2^k) it will take (n) for all k = 1 to k. and k will go up to logn. Hence its TC should be O(nogn).
1
1

1 Answer

0 votes
0 votes

Time complexity will depend on statement.