This module introduces common algorithmic patterns over lists.
- Difficulty: Intermediate.
- Estimated Time: 30-45 minutes.
- Prerequisites:
01-foundations/arrays-and-vectors,01-foundations/functions. - Cross-Language Lens: Compare hand-written loops with library helpers and see when explicit iteration stays clearer for beginners.
python example/main.py- Linear search for the first matching index.
- Counting occurrences of a target value.
- One-pass minimum and maximum scanning.
- Combining multiple statistics in a single loop.
- Forgetting to handle empty lists before min/max logic.
- Initializing minimum or maximum with invalid defaults.
- Doing multiple passes when one pass is enough.
- Compared with the C++ baseline, the same traversal and aggregation ideas are expressed with different defaults for loops, collections, and helper functions.
- Relative to Python, the statically typed tracks make intermediate state and accumulator types more explicit.
- The useful comparison is algorithm shape staying constant while the surrounding syntax and safety rails change.
- exercises/01.py: linear search and first index.
- exercises/02.py: minimum, maximum, and even-count in one pass.
- exercises/01.py
- Input: integer
n, thennvalues, then a target. - Output: first index of target or
-1. - Edge cases:
n <= 0; target not present.
- exercises/02.py
- Input: integer
n, thennvalues. - Output: minimum, maximum, and even count.
- Edge cases: all odd numbers (even count
0); all equal values.
- I can implement linear search confidently.
- I can compute multiple statistics in one pass.
- I can reason about edge cases before coding.
- I completed exercises/01.py.
- I completed exercises/02.py.