0

I have this jump search algorithm, and I have to analyze its time complexity in the worst case scenario

def find_me(search_object, array):
    n = len(array)
    lower = 0
    upper = n - 1
    while lower <= upper:
        idx = (lower + upper) // 2
        if search_object < array[idx]:
            upper = idx - 1
        elif search_object > array[idx]:
            lower = idx + 1
        else:
            return idx
    raise ValueError("Value is not in the list"

It looks to me as it has a O(n) linear complexity, as when I analyze the the steps:

3 x assignation while loop that runs n times 1 x n assignation 3 x n asignations

Olaola
  • 29
  • 7

0 Answers0