Physics I / Searching and sorting ideas
Practice question · Multiple choice

Binary search is far faster than linear search but is used less often in practice. Why is it used less often than its speed would suggest?

Hints
  1. Ask what has to be true before binary search can start.
  2. Compare the cost of sorting once with the cost of one scan.
Show the answer

B. It requires the data to be sorted, which costs more

Why

The precondition is the cost. Sorting is O(nlogn)O(n\log n) and a scan is O(n)O(n), so for one lookup the scan wins, binary search pays off across repeated queries.

Read the lesson: Searching and sorting ideas →

Practise Searching and sorting ideas

The app has 8 more questions on this lesson, and keeps your place in the course. Physics I is free to start.

More questions on Searching and sorting ideas