F12 · Topic 3.9
Algorithm comparison
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
- Input 12,7,3,7,0Waiting
- 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
| Input | Expected | Why this case |
|---|---|---|
| [2,7,3,7,0]; threshold 5 | Counts 2,2; first position 2 | One matching run is not a proof. |
| [0,0,8]; threshold 5 | Counts 1,1; first position 3 | Separates output meanings. |
| []; threshold5 | Counts 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.