Devora

Code Tracer

Trace code execution step-by-step or run the real program.

Binary Search

Input

[1, 3, 5, 7, 9, 12, 15]
Python
1def binary_search(arr, target):
2 low = 0
3 high = len(arr) - 1
4
5 while low <= high:
6 mid = (low + high) // 2
7
8 if arr[mid] == target:
9 return mid
10 elif arr[mid] < target:
11 low = mid + 1
12 else:
13 high = mid - 1
14
15 return -1

Current Line

Line

Variables

Run the tracer to see variables.

Call Stack

binary_search(arr, target)

Output

No output yet