Searching Algorithm Visualizations: Linear Search and Binary Search
Searching is one of the first algorithms every programmer learns. These two simulations let you search your own list: linear search checks items one at a time and works on any list, while binary search halves a sorted list at every step. Compare the number of comparisons for best, average and worst cases and see why sorting first can pay off.
2 interactive simulations
Frequently asked questions
When should I use binary search instead of linear search?
Use binary search on a sorted list you will search many times — it needs about log₂ n comparisons. Use linear search on unsorted or very small lists.
Does binary search work on unsorted data?
No. It relies on the sorted order to discard half of the remaining items at each step.