Mysterious Function

Chris received the following algorithm written in Python :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
def mysterious(L,i,j):
    if i + 1 == j:
        return -INF

    mid = (i + j) / 2

    x = max(L[i:mid])
    y = max(L[mid:j])
    if x == y:
        return x

    if x > y:
        return max(mysterious(L,i,mid),y)
    else:
        return max(mysterious(L,mid,j),x)

It takes in an integer list \(L\) and initially \(i=0\) and \(j=\text{len}(L) > 1\). What does this algorithm returns?

Details and Assumptions

  • Assume that INF is larger than any integer in \(L\).
×

Problem Loading...

Note Loading...

Set Loading...