C19 · Topic 3.2 · 40 minutes · AAP-1.C, AAP-1.D
Representing a collection
By the end you can:
- Represent ordered data with a list.
- Explain duplicates and empty collections.
- Choose a representation for a stated purpose.
Before this lesson: topics 3.1.
- List
- An ordered collection of elements referenced as one value.
- Data abstraction
- Representing a collection so code can use it without naming a separate variable for each element.
Understand
A list groups related values under one name while preserving an order. Each occurrence is an element, so repeated values are not automatically merged. An empty list is a valid collection with length 0, not evidence of an error unless the programme’s contract forbids it.
Data abstraction helps a programme work with a collection through its operations rather than a fixed set of separate variable names. Choose what each element represents and what order means. A list of capacities alone does not automatically preserve which room each capacity belongs to if that association is needed.
Worked example
capacities←[2,7,3,7,0]records five clubs in catalogue order.
- The list has five elements even though 7 occurs twice.
- A zero capacity is a real full club, not a missing value.
- If names must be displayed, preserve an explicit association with each club rather than treating equal capacities as the same club.
Explore each concept
Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.
- List order and duplicates
- Generic traversal versus separate variables
- Preserving associations
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
- Collection size (0–8)3Waiting
- RepresentationlistWaiting
Ready to explore: Grow a collection without rewriting the algorithm
Why: Change an input, predict the first effect, then advance one step.
Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.
Step through and experiment
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.
Check a misconception
Claim: A list keeps only distinct values.
A list can contain repeated values at different positions.
Guided practice
Give the length and explain the two 7 sin this list.
Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.
Independent transfer
How would you represent no available recommendations without inventing a room?
Exit check
Name one representation decision the developer must document.
Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.
Check yourself
Your practice so far
Check an answer to see its rationale.