This kind of recursion is similar to a binary search, but I'm not sure how to exactly solve the recursion using back substitution.
To find the index where it is equal to the array value (in a sorted array), the code would basically look like this:
find(array, low, high) {
if high < low
return -1
mid = (low + high) / 2
midval = array[mid]
if midval == mid
return mid
int left = find(array, low, min - 1)
if left >= 0
return left
int right = find(array, mid + 1, high)
return right
}
So the recurrence relation would look like this:
T(1) = b
T(n) = 2T(n/2) + c
= 4T(n/4) + c(1+2)
= 8T(n/8) + c(1+2+4)
= 16(n/16) + c(1+2+4+8)
= 2^k T(n/2^k) + (2^k - 1)c
= 2^(logn)T(1) + (2^(logn) - 1)c
= 2^(logn)(1+c) - c
I know the time complexity is suppose to be like O(logn) or O(nlogn), but I'm not sure how to get there from this using back subtitution.