DSA Visualizer
Binary search, step by step
Every comparison eliminates half of what's left. That's why binary search reaches a result in O(log n) comparisons instead of scanning every element.
The array is always sorted first — binary search only works on sorted data. Try 50: it isn't in the array, so you can watch the search correctly conclude that.
3
07
111
219
323
431
540
652
761
878
985
1093
11Step 1 of 9
Searching for 52 in a sorted array of 12. Binary search starts by looking at the middle of the whole range.
Put this into practice
Connect the idea to a worked lesson, a practical task or your interview preparation.
- Concept guideBig O Notation →A way to describe how an algorithm's time or memory use grows as its input grows, independent of any specific machine.
- Practice problemBinary Search →Solve this easy problem with samples, hints and checks in your browser.
- LessonPython Lists →Learn how Python lists store ordered, changeable collections of values, and how to create, access, modify, and iterate over them.
- Interview prepCoding & DSA interview questions →The concepts behind data-structure and algorithm interview questions — paired with the practice problems that let you actually write the code.
Last updated: