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
print("reached here")
return Mystery2(A, m+1, l)
The precondition is given as: A is an array of integers, and f$f$ and l$l$ are integers 0 <= f <= l < len(A)$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 (l-f+1)/2$ \frac{l-f+1}{2}$ times or A[l]. I'm
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)$T(n)$ being the worst runtime of the function and n = l-f$n = l-f$, T(n)$T(n)$ will be constant if n = 0$n = 0$ and T(floor(n/2)) + T(ceiling(n/2) - 1) + n*c_1 + c$T(\left \lfloor \frac{n}{2} \rfloor \right) + T(\left \lceil \frac{n}{2} \right \rceil - 1) + n*c_1 + c$, if n is greater than 0$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!