Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1comparisons = n | AWorst case for a linear search: the target is the last item or missing, so all n items are checked (1000 items means up to 1000 comparisons). | |
| 2comparisons ≈ log2 n | BWorst case for a binary search: each comparison halves the range, so 1000 sorted items need only about 10 comparisons. | |
| 3Binary search halves the remaining range each time, so it needs far fewer comparisons than linear search on a big sorted list. | CAbout 10 comparisons is the binary search figure. A linear search may need up to 1000 comparisons (n) in the worst case. | |
| 4Binary search only works on sorted data, so sorting first adds a cost that linear search does not have. | DBinary search does not check half of the items. It halves the range again and again, so it needs only about 10 comparisons (log2 1000). | |
| 5A linear search of 1000 items needs about 10 comparisons in the worst case. | EIF list[middle] < target THEN low ← middle + 1 | |
| 6Binary search needs 500 comparisons for 1000 sorted items because it checks half of them. | Fmiddle ← (low + high) DIV 2 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
log2 n — Worst-case comparisons for binary search: it halves a sorted range, so 1000 items need about 10 steps. Linear search needs up to n, so 1000 items could need 1000 comparisons.worstLinear ← nworstBinary ← log2(n)n ← 1000
linearMax ← n
binaryMax ← 10IF dataSorted = TRUE THEN
steps ← log2(n)IF log2(n) < n THEN
OUTPUT "Binary search is faster"