Skip to main content
AP CSP course

F12 · Topic 3.9

Algorithm comparison

Compare two full-traversal counters with a first-match algorithm and justify a real equivalence rather than trusting a few matching runs.

1. Predict first

For[2,7,3,7,0]and threshold 5, predict a counter adding qualifying entries, a counter subtracting nonqualifying entries from list length, and the first qualifying AP position.

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 12,7,3,7,0Waiting
  2. Input 25Waiting

Ready to experiment

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

Try this: Try repeated boundary values, no matches and an empty list.

2. Build your procedure

Write both counting algorithms and a counterexample where first-position differs from count. Explain the invariant behind the two equivalent counts.

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
[2,7,3,7,0]; threshold 5Counts 2,2; first position 2One matching run is not a proof.
[0,0,8]; threshold 5Counts 1,1; first position 3Separates output meanings.
[]; threshold5Counts 0,0; first position 0(absent)All algorithms must define the empty case.

4. Explain and reflect

How would you combine filtering and counting without assuming they return the same data type?

Model limits: Runs three stated algorithms on bounded lists. Agreement in the tool is evidence for cases, while the partition argument justifies the counting equivalence generally.

Teacher guidance and scoring