Skip to main content
⚙️Algorithmsbeginner

Question 1 of 10

def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    steps = 0
    while left <= right:
        mid = (left + right) // 2
        steps += 1
        if arr[mid] == target:
            return steps
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

print(binary_search([1, 3, 5, 7, 9], 7))

What's the output?

Tech School/Quiz/Algorithms (Beginner)