Selection and Iteration
Conditions choose paths and loops revisit paths. Together they express searches, counts, simulations, string processing, and most other algorithms in the course.
- Exam weight
- 25–35%
- Topics
- 12
Introduction
Conditions choose paths and loops revisit paths. Together they express searches, counts, simulations, string processing, and most other algorithms in the course.
Correct tracing depends on execution order. Evaluate a condition only when control reaches it, record every state change, and identify the invariant that remains true after each complete iteration. Then prove termination by naming the value that moves toward an exit.
Algorithms with Selection and Repetition
How do decisions and repeated steps turn a straight-line procedure into an algorithm?
Selection chooses which steps run from current conditions, while iteration repeats steps until a bound or stopping condition is reached.