Binary Search Demonstration

Sorted Array (20 numbers)

Binary search requires a sorted array. This array is already sorted in ascending order.

Binary Search Demonstration

Try searching for a number that exists in the array, or one that doesn't!

Enter a number above and click "Start Search" to begin the binary search demonstration.

How Binary Search Works:
  1. Binary search requires a sorted array
  2. Start with the entire array as the search range
  3. Compare the target with the middle element
  4. If found, return the index
  5. If target is smaller, search the left half
  6. If target is larger, search the right half
  7. Repeat until found or the range is empty

Time Complexity: O(log n) - Much faster than linear search!

Learn about Linear Search Learn about Selection Sort