Consider the following recurrence relation:
What will be complexity of above relation?
(A) O(n)
(B) O(√n )
(C) O(log2n)
(D) O(nlog2n)
Answer: (C)
Explanation:
T(n) = T(n / 2) + C
= T(n / 4) + C + C
= T(n / 8) + 3*C
.
.
.
N will be divided until it becomes 1. So,
= T(n / 2k) + (k-1) * C
That means, n / 2k = 1
= k = log2n
T(n) = 1 + (log2n - 1) * C
T(n) = O(log2n)
So, option (C) is correct.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...