I was looking for the worst-case and best-case run-time analysis of the following recurrence relation:
T(n) = 2T(n/2) + T(n-1) + 1
I couldn't find strictly the same question on Stack Overflow or on the Web.
In this case, we have three branches, and we know that T(n/2)
would reach the base case faster than T(n-1)
would, so from my understanding, the longest leaf to root path represents the worst-case complexity and the shortest leaf to root path represents the best-case complexity.
As such, we have that the best case complexity would be:
T(n) = log(n) * T(1)
Assuming that T(1)=1
, then we have best-case complexity
T(n) = O(logn)
If we look at the worst case complexity, we have
T(n) = n * T(1)
So, then we have (by assuming T(1)=1
again):
T(n) = O(n)
Could I be misunderstanding something here or is this timing analysis accurate for this recurrence relation?