Binary Search Visualizers

12

Step through every Binary Search problem with animated runtime state, source highlighting, and curated test cases. Built for coding-interview prep and durable algorithmic intuition.

Binary Search
Shrink the sorted search window until the middle element either matches the target or the interval disappears.
Binary Search
Find First and Last Position of Element in Sorted Array
Run binary search twice: once for the left boundary and once for the right boundary of the target.
Boundary Binary Search
Find K Closest Elements
Binary search the starting index of the best k-length window instead of comparing each element independently.
Binary Search on Window Start
Find Minimum in Rotated Sorted Array
Compare mid with the right boundary to decide whether the minimum is in the rotated right block or the sorted left block.
Pivot Binary Search
Find Peak Element
Compare mid with its right neighbor; the slope tells you which side must contain a peak.
Slope Binary Search
First Bad Version
Search for the leftmost bad version by keeping bad mids and discarding everything before good mids.
Left Boundary Binary Search
Guess Number Higher or Lower
Treat the feedback API as the comparison oracle and keep halving the remaining guess range.
Binary Search with Oracle
Median of Two Sorted Arrays
Find the median of two sorted arrays in O(log(min(m,n))) time by binary searching the optimal partition index between them.
Binary Search on Partitions
Peak Index in a Mountain Array
Binary search the turning point where the increasing slope switches into a decreasing slope.
Mountain Peak Binary Search
Search in Rotated Sorted Array
At every step, one half of the rotated array is still sorted. Detect it and decide whether the target lies there.
Binary Search on Rotated Array
Single Element in a Sorted Array
Use index parity around matched pairs to tell which side still has the broken pairing pattern.
Parity Binary Search
Sqrt(x)
Binary search the integer answer space and keep the largest mid whose square does not exceed x.
Binary Search on Answer