Past exam question: 2066 Jestha (Back), Q8(b)
Open in the Padhaiko appQuestion
Compare the sequential search and binary search in terms of Big 'O' notation with an example.
Solution
Big-O Comparison of Sequential vs. Binary Search:
- Sequential Search: worst/average case, best case. Works on any (sorted or unsorted) array/list.
- Binary Search: worst/average case, best case. Requires a sorted random-access array.
Example: Searching for 99 in a sorted 1,024-element array takes up to 1,024 comparisons in sequential search () versus at most comparisons in binary search ().
Answer:
Sequential search is (works on unsorted data), while binary search is (requires sorted data)—requiring at most vs. comparisons on 1,024 items.