Practice question · Select all that apply
Select every true statement about binary search.
Hints
- Separate the properties of binary search from those of linear search.
- 'Works on any collection' is linear search's advantage, not binary search's.
Show the answer
- A. Binary search requires the data to be sorted.
- C. Scanning from one end costs O(log n) when the item is last.
- D. Sorting first pays off when many searches will follow.
- E. Unsorted data is no obstacle to a linear scan.
Why
Binary search needs sorted data and random access, halves the range each step, and is O(log n). Working on any unsorted collection describes linear search, which is the option that does not belong.
Practise Searching Strategies
The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Searching Strategies
- Binary search on a million sorted items needs about 20 comparisons; a linear scan needs up to a million. Why…
- Binary search is O(log n), so searching an unsorted array once is faster if you sort it first.
- Order the 'invest structure to buy speed' workflow the lesson describes for searching a fixed dataset many…