Interactive Learning Lab
Algorithm Step Debugger
Pick a core pattern, enter your own numbers, and step through each line in Rust, PHP, JavaScript, Python, or Go.
Category:
Binary Search
Halve the search window [low..high] on every comparison until target is found.
init← / → or Space
Initialize window [0 .. 6]
Start with low = 0 and high = 6. We are looking for target = 23.
Array State
2
[0]low
5
[1]8
[2]12
[3]16
[4]23
[5]38
[6]high
Variable Watch
target23
low0
high6
mid—
val—
Line 2
1pub fn binary_search(nums: &[i32], target: i32) -> i32 {2 let (mut low, mut high) = (0isize, nums.len() as isize - 1);3 while low <= high {4 let mid = low + (high - low) / 2;5 let val = nums[mid as usize];6 if val == target {7 return mid as i32;8 } else if val < target {9 low = mid + 1;10 } else {11 high = mid - 1;12 }13 }14 -115}