Quarry School

Trace a decision

Subject: Computing
Level 1 · FoundationsAbout 6 min read3 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

    A library desk has a rule for late books, invented for this lesson.

    Rule

    At a selection step, work out the condition with the current values each time the step is reached. If it is true, carry out the action the step gives for true. If it is false, carry out the step's otherwise action when it has one. After either, follow any instruction about where to go next, and continue with the next step in order when there is none. The condition decides which action is carried out.

    Step

    1. Draw a table with a column for the step, a column for the condition with its values filled in and a column for what the procedure holds after the step.

    2. Write the input above the table.

    3. Carry out the steps in order. At a selection step, copy the condition with the real values in place of the names.

    4. Write true or false beside the condition. If it is true, do the action the step gives for true. If it is false, do the step's otherwise action when it has one. After either, follow any instruction about where to go next, and move to the next step in order when there is none.

    5. Stop at the step that says stop. The output is what that step announces.

    6. Trace again with inputs that take the other paths: one input that makes each selection step's action run, and one for which no condition is true. For the late-fee procedure, 0, 3 and 8 days late do that.

    Trap

    Do not skip a step because the answer seems clear. Carry out every step the procedure reaches, including the ones whose condition is false.

    The opposite slip is carrying out an action whose condition was false, or going on to step 3 after step 2 has said go to step 5. For 0 days late that slip announces 1 coin where the rule gives 0. Sequencing means carrying out the steps in the order the procedure gives them. Follow each jump as written.

    1 In plain words

    A library desk has a rule for late books, invented for this lesson. A book returned on time costs nothing. A book up to a week late costs a small fee, and a book more than a week late costs a larger one. The clerk asks one question at a time and acts on the answer.

    In an algorithm, selection means that a condition decides which steps are carried out. A condition is a question whose answer is true or false, like the predicates in the last unit.

    The late-fee procedure has five steps. Step 1: read the number of days late. Step 2: if the number is 0, the fee is 0 coins, and go to step 5. Step 3: if the number is 7 or less, the fee is 1 coin, and go to step 5. Step 4: the fee is 3 coins. Step 5: announce the fee and stop. Steps 2 and 3 are selection steps, because a condition decides whether their action is carried out.

    To trace a procedure is to carry it out by hand for one input and write down what happens at each step.

    Remember one sentence: at a decision, write the condition with the real values, then true or false. That method is this lesson's own. For selection, find essential knowledge AAP-2.G.1 in the AP Computer Science Principles Course and Exam Description.

    2 Picture it

    Days lateFirst trueFee0step 203step 317step 318neither3

    A table of four inputs to the late-fee procedure. For 0 days late the condition in step 2 is true and the fee is 0. For 3 days late the condition in step 3 is the first true one and the fee is 1. For 7 days late the condition in step 3 is again the first true one and the fee is 1. For 8 days late neither condition is true and the fee is 3. The rows for 7 and 8 are marked.

    Four inputs and the first condition each one makes true

    3 Why

    A condition is worked out with the values the procedure holds at that moment. For 8 days late, step 2 asks whether 8 is 0. The answer is false, so the action is skipped and the next step in order is carried out. Selection picks the parts of an algorithm to carry out from whether a condition is true or false.

    The words go to step 5 matter as much as the conditions. For 0 days late, step 2 sets the fee to 0 and jumps to step 5. Without that jump the tracer would reach step 3, where 0 is 7 or less, and the fee would change to 1. The order of the steps is part of the algorithm.

    4 The rule

    At a selection step, work out the condition with the current values each time the step is reached.

    If it is true, carry out the action the step gives for true. If it is false, carry out the step's otherwise action when it has one. After either, follow any instruction about where to go next, and continue with the next step in order when there is none. The condition decides which action is carried out.

    5 How

    1. Draw a table with a column for the step, a column for the condition with its values filled in and a column for what the procedure holds after the step.
    2. Write the input above the table.
    3. Carry out the steps in order. At a selection step, copy the condition with the real values in place of the names.
    4. Write true or false beside the condition. If it is true, do the action the step gives for true. If it is false, do the step's otherwise action when it has one. After either, follow any instruction about where to go next, and move to the next step in order when there is none.
    5. Stop at the step that says stop. The output is what that step announces.
    6. Trace again with inputs that take the other paths: one input that makes each selection step's action run, and one for which no condition is true. For the late-fee procedure, 0, 3 and 8 days late do that.

    6 Trace

    Trace the late-fee procedure for 8 days late
    StepConditionFeeExplanation
    1—not setThe input is 8 days late.
    28 is 0: falsenot setThe condition is false. Skip the action and go on to step 3.
    38 is 7 or less: falsenot setFalse again. Go on to step 4.
    4—3Step 4 has no condition. The fee is 3 coins.
    5—3Announce 3 and stop.

    7 The trap

    Do not skip a step because the answer seems clear. Carry out every step the procedure reaches, including the ones whose condition is false.

    The opposite slip is carrying out an action whose condition was false, or going on to step 3 after step 2 has said go to step 5. For 0 days late that slip announces 1 coin where the rule gives 0. Sequencing means carrying out the steps in the order the procedure gives them. Follow each jump as written.

    Quick checks

    Quick check 1 of 2

    Trace the late-fee procedure for 7 days late. Which condition is false, which is true, and what fee is announced?

    Show the steps and the answer
    Answer

    The condition in step 2 is false and the condition in step 3 is true. The fee announced is 1 coin.

    Why: 7 is not 0, so step 2's action is skipped. 7 is 7 or less, so step 3 sets the fee to 1 and jumps to step 5.

    Source: College Board, AP Computer Science Principles Course and Exam Description

    Quick check 2 of 2

    A tracer forgets the words go to step 5 at the end of step 2 and carries on in order. What fee do they announce for 0 days late, and what fee does the procedure as written announce?

    Show the steps and the answer
    Answer

    They announce 1 coin. The procedure as written announces 0 coins.

    Why: Step 2 sets the fee to 0. Without the jump the tracer reaches step 3, where 0 is 7 or less, so the fee becomes 1 and step 3 sends them to step 5.

    Source: College Board, AP Computer Science Principles Course and Exam Description

    Sources

    1. AP Computer Science Principles Course and Exam Description. College Board. All rights reserved. Read 1 Dec 2026.