I just wanted to make sure I'm on the right track regarding this.
Here's the function that I'm dealing with:
import math
def Mystery2(A, f, l):
if f == l:
return A[f]
m = math.floor((f+l)/2)
x = Mystery2(A, f, m)
c = 0
i = f
while i <= l:
if A[i] == x:
c = c + 1
i = i + 1
if c > (l-f+1)/2:
return x
return Mystery2(A, m+1, l)
The precondition is given as: A is an array of integers, and $f$ and $l$ are integers $0 \leq f \leq l < len(A)$.
From what I can see by running the function, the postcondition appears to be that it outputs the element within f and l indices that occurs more than $ \frac{l-f+1}{2}$ times or A[l].
I'm not sure how to find a closed form for the recurrence relation representing the worst case runtime.
So far I figured that with $T(n)$ being the worst runtime of the function and $n = l-f$, $T(n)$ will be constant if $n = 0$ and $T(\left \lfloor \frac{n}{2} \rfloor \right) + T(\left \lceil \frac{n}{2} \right \rceil - 1) + n*c_1 + c$, if $n > 0$. I'm not sure how to convert this into a closed form.
Is it okay to simplify this into $T(\left \lfloor \frac{n}{2} \rfloor \right) + T(\left \lceil \frac{n}{2} \right \rceil) + n*c_1 + c$ for the purpose of comparing it to the master theorem?
Thanks in advance for any help