Quarry School

Compare work as the collection doubles

Subject: Computing
Level 1 · FoundationsAbout 5 min read2 new terms
How this was estimated

Programmatic estimate. Rung levels, worked steps, prerequisites, terms and sentence length contribute to this level. It describes the lesson, not your ability.

Reading counts the whole lesson, including folded explanations, at 180 words a minute. Practice allows two minutes per item. These are planning assumptions; take the time you need.

AI estimate unavailable.

Path to here

Open the unit’s lesson list to follow the lesson order.

    Quick review (2 minutes)

    In plain words

    An algorithm's efficiency estimates the work it does, and it is stated in terms of the size of the input.

    Rule

    To compare the efficiency of two procedures, count a step, such as a comparison, as a function of the input size. When a row doubles, a linear search's worst case doubles, a binary search's grows by one check, and, from 4 cards on, selection sort's count grows a little more than four times.

    Step

    1. Choose the measure of size, such as the number of cards, and the step to count, such as a comparison.

    2. Write the worst-case count for one size.

    3. Double the size and write the worst-case count again.

    4. Compare the new count with the old one to see how the count grows.

    5. Compare the growth of the procedures, not their counts on one small input.

    Trap

    Comparing one small input hides the difference. On 3 cards the two searches make at most 3 and at most 2 comparisons, but on 63 cards they make at most 63 and at most 6. Compare how the counts grow.

    A best case can also mislead. A linear search whose target sits on the first card makes one comparison at any size; the worst case, a target absent from the row or first found on the last card, shows the cost of a big row.

    1 In plain words

    An algorithm's efficiency estimates the work it does, and it is stated in terms of the size of the input. One informal measure counts how many times a step runs. In this unit the size is the number of cards and the step counted is a comparison, in the worst case: the input that makes a procedure work hardest, as the Field Guide's searches count their most checks.

    Different correct algorithms for the same problem can have different efficiencies. This lesson sees the difference by doubling the size of the input and comparing the counts.

    Remember one sentence: count the comparisons, then double the cards and count again. To look it up, see essential knowledge AAP-4.A.3, AAP-4.A.5 and AAP-4.A.6 in the AP Computer Science Principles Course and Exam Description.

    2 Picture it

    CardsLinear worstBinary worst151543131563636

    A table of the worst-case comparisons of linear and binary search. A sorted row of 15 cards needs at most 15 comparisons for linear search and 4 for binary search. A row of 31 cards needs at most 31 and 5. A row of 63 cards needs at most 63 and 6. The row for 63 cards is marked.

    Worst-case comparisons of the two searches as the row grows

    3 Why

    A linear search's worst case checks every card, so twice the cards means twice the comparisons. A binary search's first check, when it misses, removes the middle card and one side of the rest, so it leaves at most as many cards as before the doubling, and the worst case grows by one check. The Field Guide states the same: doubling the boxes doubles the most checks a linear search makes and adds one to the most a binary search makes.

    Selection sort grows faster than both. Its count is 1 + 2 + ... up to one less than the number of cards: 28 comparisons for 8 cards, and 120 for 16. From 4 cards on, doubling the cards multiplies the count by a little more than four, closer to four as the rows grow.

    A single small input can mislead. On 3 cards a linear search makes at most 3 comparisons and a binary search at most 2, which looks like little difference. The counts for growing inputs show which procedure keeps up.

    4 The rule

    To compare the efficiency of two procedures, count a step, such as a comparison, as a function of the input size.

    When a row doubles, a linear search's worst case doubles, a binary search's grows by one check, and, from 4 cards on, selection sort's count grows a little more than four times.

    5 How

    1. Choose the measure of size, such as the number of cards, and the step to count, such as a comparison.
    2. Write the worst-case count for one size.
    3. Double the size and write the worst-case count again.
    4. Compare the new count with the old one to see how the count grows.
    5. Compare the growth of the procedures, not their counts on one small input.

    6 Trace

    Selection sort's comparisons as the row doubles
    CardsComparisonsTimes the count beforeExplanation
    46—3 + 2 + 1 is 6.
    828about 4.77 + 6 + 5 + 4 + 3 + 2 + 1 is 28, and 28 / 6 is about 4.7.
    16120about 4.3The sum of 1 to 15 is 120, and 120 / 28 is about 4.3.
    32496about 4.1The sum of 1 to 31 is 496, and 496 / 120 is about 4.1.

    7 The trap

    Comparing one small input hides the difference. On 3 cards the two searches make at most 3 and at most 2 comparisons, but on 63 cards they make at most 63 and at most 6. Compare how the counts grow.

    A best case can also mislead. A linear search whose target sits on the first card makes one comparison at any size; the worst case, a target absent from the row or first found on the last card, shows the cost of a big row.

    Quick checks

    Quick check 1 of 2

    A linear search of a row of 40 cards makes at most 40 comparisons. At most how many does it make on a row of 80 cards?

    Show the steps and the answer
    Answer

    At most 80 comparisons.

    Why: The worst case checks every card, so doubling the cards doubles the worst-case count.

    Source: University of Canterbury Computer Science Education Research Group, Computer Science Field Guide: Algorithms, 2.2 Searching

    Quick check 2 of 2

    A binary search makes at most 5 checks on a sorted row of 31 cards and at most 6 on 63 cards. At most how many does it make on a sorted row of 127 cards?

    Show the steps and the answer
    Answer

    At most 7 checks.

    Why: 127 cards are 63 doubled plus one. The first check reads the middle card, the 64th, and leaves at most 63 cards, which need at most 6 more checks.

    Source: University of Canterbury Computer Science Education Research Group, Computer Science Field Guide: Algorithms, 2.2 Searching

    Sources

    1. AP Computer Science Principles Course and Exam Description. College Board. All rights reserved. Read 2 Dec 2026.
    2. Computer Science Field Guide: Algorithms, 2.2 Searching. University of Canterbury Computer Science Education Research Group. CC BY-SA 4.0. Read 2 Dec 2026.
    3. Computer Science Field Guide: Algorithms, 2.3 Sorting. University of Canterbury Computer Science Education Research Group. CC BY-SA 4.0. Read 2 Dec 2026.