Report an Error

Reported page · Common Mistake

Using Linear Search When Binary Search Needs Sorted Data

/mistakes/computer-science-using-linear-search-when-binary-search-needs-sorted-data/

or drop them here

Up to 3 images or PDFs, 5 MB per file. 0 of 3 attached.

Save resource to class

Loading your classrooms…

Computer Science

Using Linear Search When Binary Search Needs Sorted Data

Students run binary search on an unsorted array and expect it to work like a faster linear search.

Quick check

Why students make it

Binary search feels like it is just skipping ahead to save time. The missing idea is that each skip is only valid when the data is sorted in the same order the search uses.

The rule done right

Use binary search only when the collection is sorted by the search key. If the data is not sorted, use linear search, or sort it first and then use binary search.