Why can two correct search procedures take very different amounts of work?
Correctness says whether the method returns the right answer. Work depends on what each comparison reveals and on assumptions about the data. In an ordered list that can be indexed directly, comparing with the middle can discard half of the remaining region. An unordered scan can usually discard only what it has already inspected.
Comparing methods fairly means naming what they cost and what information they assume. Fast repeated queries can depend on earlier work organizing the data.
Start with the question
The answer, the explanatory gap and useful foundations.
Read in your own way
Start with the answer, refresh a foundation when you need it, or follow the explanation through. Read the ordered explanatory sections and check their stated sources and limits.
Everything here is open without an account. Saving is optional. The public subject tree is a map of published ideas; My Forest contains the subjects you choose to plant.
See the public Computer Science tree →A foundation, without a detour.
A search procedure receives a target and returns whether it occurs in a collection. Count inspections of item values in a list you can reach at any position.
An invariant survives a step
When an inspection is finished, every place that might still contain the target must remain under consideration. Both methods below preserve that condition.
Develop the model
Follow the first explanatory steps without losing their qualifications.
Scan the register
Imagine a museum whose storage drawer labels are recorded as numbers. Eight labels are 11, 18, 24, 33, 41, 54, 68 and 72. The registrar asks whether 68 appears. Read from left to right and stop at a match. A plain scan reports success at the seventh inspection. Every unsuccessful comparison has resolved just one position. If the labels were in any order, passing a larger value would tell you nothing about the later ones.
This plain procedure also handles absence. After the final inspection, every position has been ruled out. For eight items that can mean eight inspections. For eighty it can mean eighty. Correctness follows because it never ignores an unexamined possibility.
A scan trades a simple guarantee for potentially many inspections.
Use the fact that the list is ordered
The stored list happens to be increasing. Compare the target with 33, the fourth value and the lower of its two middle choices. Every label at or before 33 is too small, so remove those four positions. Now consider 41, 54, 68 and 72. Inspect 54, again the lower middle. Rule out 41 and 54 together. Compare 68 with the lower middle of the two remaining values and stop at a match. For this target the ordered procedure makes three inspections.
The key is the reason each discarded interval is impossible. Whenever its middle is below the target, every value to its left is also below. Whenever the middle is above, every value to the right is also above. If the list is out of order, the same rule can discard a true match and no longer proves correctness.
Order makes one comparison answer a question about many positions.
Investigate and refine
Predict, compare the lenses and carry the explanation further.
The next sections refine the explanation. No interactive investigation has been attached to this publication.
Count what happens as the list grows
Each comparison with a middle value leaves no more than half the earlier positions if it does not find the target. A register that starts around twice as long needs roughly one more worst-case halving step. In contrast, a scan can examine every added entry. This comparison concerns growth in value inspections, rather than exact milliseconds.
The current scan would find 11 immediately, while the binary method would first inspect a different value. That does not contradict the worst-case argument. It shows why a method should be compared across scenarios and input sizes. A benchmark of just one easy target cannot tell you what happens when the target is hidden near the end or absent.
Worst-case growth is a guarantee about possible work, not the cost of every lookup.
Include the work that made search possible
A register that is rarely searched, often changed and originally unsorted may not justify sorting it for one answer. If its order can be maintained across many searches, the initial effort can be worthwhile. Also ask how a program reaches the middle. In this example each position is directly available. If you must step through connected records to reach the middle, the few comparisons do not account for all the movement.
The registrar can now explain two true outcomes without calling one method universally superior. The scan needs little setup. The ordered search acts on a maintained promise about the register and makes comparisons more informative. Both give the same yes or no when used under the right assumptions.
Include preparation and access costs when choosing an approach.
Apply and connect
Try a new case, follow genuine relationships and check the sources.
Consider another case.
When do many queries repay the work of building and maintaining an index?
No assessment item is attached. Reading or marking this explanation studied does not award assessment evidence.
A useful explanation has edges.
- The example counts comparisons, not elapsed time or memory usage. It does not model a database index.
- This search answers existence. Finding the first of several equal labels requires a specified tie policy and a slightly different stopping rule.
Follow the concepts.
A map can help you find a useful foundation or a different view. Every line below has a stated reason and a limit.
No direct published relationship is recorded for this selection yet. No connection is invented to fill the diagram.
Find a connected question with Seed Shuffle →Sources & authorship
This explanation was released through an explicit editorial review. Structural checks and an Owner or delegated editorial decision are not independent expert or scientific certification.
The sources below identify claim scope and consultation dates. Check the original material and its limits.
- Harvard CS50x 2026, Lecture 3 ↗
Linear search checks a succession of values. Binary search uses ordered values to eliminate regions. The count of comparisons in the original Manthoryn example is derived separately.
Source consulted 2026-11-17
Lesson lesson.computer-science.search-work · Revision 1.0.0. Found a problem? Raise a content concern. This prepares a local note; no report is delivered by opening it.