Skip to main content
AP CSP course

F07 · Topic 3.1 · 3.3

Variable trace studio

Trace changing state and an arithmetic expression, and compare a destructive overwrite with a swap that preserves both originals.

1. Predict first

Start a 4,b 9. Predict a←b; b←a. Then predict temp←a; a←b; b←temp using a fresh copy of the starting values.

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 14Waiting
  2. Input 29Waiting
  3. Input 35Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Change one input, predict the difference, then reset and compare.

2. Build your procedure

Write a state table for both sequences, including temp. Then calculate (a+2*b) MOD divisor from the original inputs and state the order of operations.

Use AP CSP pseudocode, a language you know, or precise plain language. Your code is not executed here. Use the classroom assignment to save your response.

3. Check boundaries

Public worked tests for the fixed model
InputExpectedWhy this case
a4,b9,divisor5Overwrite[9,9]; swap[9,4]; expression 2Distinct initial values expose lost state.
a7,b7,divisor3Both sequences[7,7]; expression 0Equal values conceal the swap defect.
a0,b5,divisor2Swap[5,0]; expression 0Zero remains a valid value.

4. Explain and reflect

Why is one test with equal input values insufficient to distinguish the two swap algorithms?

Model limits: Traces fixed assignment sequences and a specified arithmetic expression. It never executes submitted code.

Teacher guidance and scoring