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.
Related resources
-
Sorting Algorithms Visual Cheat Sheet Infographic -
Sorting Algorithms Infographic -
How Search Engines Work Infographic - Binary Search Variants Reference Cheat Sheet
- Sorting Algorithms Comparison Cheat Sheet
- Algorithms & Big-O Notation Cheat Sheet
- Data Structures Overview Cheat Sheet
- CS, Arrays and Lists Worksheet
- CS, Sorting Algorithms, Bubble, Selection, and Insertion Worksheet
- CS, Big-O Notation and Algorithm Efficiency Worksheet
- CS, Merge Sort and Quick Sort Algorithms Worksheet
- Java Array & ArrayList Explorer Tool
- Sorting Algorithm Visualizer Tool
- Recursion & Call Stack Visualizer Tool
- Big-O Complexity Visualizer Tool
- Searching & Sorting Performance Lab Lab
- Arrays & ArrayList Lab Lab
- Big-O & Algorithm Analysis Lab Lab
- Recursion & Data Structures Lab Lab