Skip to main content

Sequential vs binary search

Short answer

Sequential search works on sorted or unsorted data, worst O(n). Binary search requires a sorted array and direct access, worst O(log n), making it much faster for large lists.

Compare sequential search with binary search.

PointSequential (linear) searchBinary search
IdeaCompare key with each element in orderCompare with middle element, discard half
Data orderWorks on sorted or unsorted dataData must be sorted
Time (worst)O(n)O(log n)
Time (best)O(1) (first element)O(1) (middle element)
Data structureArray or linked listNeeds direct access, i.e. array
CodeVery simpleSlightly more complex
Best forSmall or unsorted listsLarge sorted lists
Average comparisonsabout (n+1)/2about log₂ n

Example: to find a key in 1,000 sorted items, sequential search may need up to 1,000 comparisons, binary search at most 10.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 8 questions →