Binary Search Visualizer

Understand how binary search works through interactive visualization

520

Algorithm Status

Generate an array and enter a target value to visualize the binary search.
Current Middle
Target Found
Searched Element
Eliminated Range

How Binary Search Works

Visual Explanation

Binary search works by repeatedly dividing the search space in half:

Sorted Array: [10, 20, 30, 40, 50, 60, 70]
Search for 30: Compare with middle (40)
10 20 30 40 50 60 70
30 < 40, search left half
10 20 30 40 50 60 70
30 > 20, search right half
10 20 30 40 50 60 70
Found 30!

Algorithm Steps

  1. 1. Start with the middle element of the sorted array
  2. 2. If target equals middle element, search is complete
  3. 3. If target < middle, search left half
  4. 4. If target > middle, search right half
  5. 5. Repeat until found or range is empty

Performance

Time Complexity: O(log n)
Space Complexity: O(1)
Key Advantage: Extremely efficient for large datasets - can search through a million elements in just ~20 comparisons