LESSON 3.07 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW
Searching and binary search
Watch binary search halve a sorted list and find 59 in 4 probes.
Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.
Go Pro · $8.25/moEXPLAINER · 3.07 · SEARCH BAYLINEAR · 14 READS · FOUND AT 13
01
Stage 1 of 6 · Linear scan
A linear search reads the items one by one from the left. It finds 59 after 14 reads.
Explain it simply
Here are 16 numbers, smallest on the left. The small number under each box is its index, its place in the row. A linear search checks each box in turn, from the left. It needs 14 reads to reach 59. A list of a million could need a million.
The list: 3, 9, 13, 17, 23, 28, 34, 39, 42, 44, 50, 50, 50, 59, 62, 67. The target x is 59. A linear search reads 14 items and finds it at index 13.
list item, target xlo, hi and middropped itemanswer, probe countlinear reads, missed item
Toy: 16 whole numbers · 3 targets · the loop of Python's bisect module · seeded
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
A linear search reads i + 1 items, or all n if x is missing.
PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
- 5 more stages and 3 live controls
- 2 mix-up cards and 3 predict-then-reveal checks
- Watch it as a narrated video, in three voices
- Every Pro lesson and capstone · 656 in total
$99 a year, or $15 a month. Cancel any time.