Binary Search — Algorithm Visualizer

Step 1:Sorted array. Searching for target: 23

Binary Search

Easy
Time Complexity
O(n²)O(n log n)O(n)O(log n)O(1)n →
Best: O(1)
Avg: O(log n)
Worst: O(log n)

Binary Search is an efficient algorithm for finding a target value in a sorted array. It works by repeatedly dividing the search interval in half.

Prerequisite: The array must be sorted.

How it works:

1. Compare the target with the middle element
2. If equal, we found the target
3. If target is smaller, search the left half
4. If target is larger, search the right half
5. Repeat until found or search space is empty

Time Complexity:

Best: O(1) — target is at the middle
Average: O(log n)
Worst: O(log n)

Space Complexity: O(1) — iterative version

Binary Search is fundamental in computer science and is used extensively in databases, file systems, and as a building block for more complex algorithms.

Related algorithms

Frequently asked questions

What is Binary Search?
Binary Search is an efficient algorithm for finding a target value in a sorted array. It works by repeatedly dividing the search interval in half.
What is the complexity of Binary Search?
Time (average): O(log n) · Space: O(1)
Who is this Binary Search visualizer for?
The Binary Search visualization targets beginner-level learners in the Searching category. Useful for students, interview prep, and hands-on review.
What algorithms are related to Binary Search?
In the same category (Searching) you can explore: Linear Search, Jump Search, Interpolation Search. Each has an interactive visualization.