May 2026 Computational Thinking — Weeks 1–4 study guide
1865 words
9 min read
2026-07-18T00:00:00.000Z
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
A method for reading procedures, modelling datasets, and tracing algorithmic state. # Computational Thinking, Weeks 1–4: procedures before syntax Computational thinking is the discipline of representing a task so precisely that another person—or a machine—can execute it without guessing.

Computational Thinking, Weeks 1–4: procedures before syntax
Computational thinking is the discipline of representing a task so precisely that another person—or a machine—can execute it without guessing. A procedure is an ordered set of instructions; a state is the complete collection of values that can change while it runs; a dataset is a structured collection of records and attributes.
Week 1 — decomposition and representation
Decomposition breaks a task into smaller operations. A good decomposition has steps that are observable, ordered, and testable. Separate the data model from the procedure: identify each record, each field, its type, and the condition that determines whether a record contributes to a result. Natural-language instructions should be made unambiguous before translating them into pseudocode.
Retrieval prompt: take a real-world task such as calculating an average. Name the data, running total, count, stop condition, and final calculation.
Week 2 — variables, predicates, and branches
A variable is a named storage location; an initialization gives it a known starting value; an update changes it deliberately. A predicate is a statement that evaluates to true or false. In a procedure, a branch should be read as a question: “under which records does this update happen?” Conditions often encode a filter.
Use a trace table with one row per record. Record the input values, predicate outcome, and each variable after the update. This catches the classic errors: updating the total but not the count, dividing before all records are processed, and assuming an empty collection cannot occur.
Predicate refresher: test, then trace
Use the logic lab to make a condition concrete. Toggle the inputs and switch gates. Then translate the predicate into a filtering sentence—for example, an AND condition might mean “the record is active and its score meets the threshold.” A gate only tells you how truth values combine; the data meaning still comes from the specification.
Loading Visualizer...
Do not confuse XOR with “or” in ordinary speech
XOR is true when exactly one input is true. In study questions, “A or B” is normally inclusive unless the wording says “but not both.”
Predicate refresher: turn the symbols back into a filter
The gate is only the beginning. In a traversal, a predicate must answer a human question about one record. Use the translation lab below to separate the main AND condition from an optional OR exception. Predict the changed row before touching a control; that prediction is the useful part of the exercise.
Loading Visualizer...
Week 3 — traversal and aggregation
A traversal visits every relevant record exactly once. The loop’s invariant often reads: “after processing the first k records, A is the total of qualifying records and B is their count.” An aggregation reduces many values to one: sum, count, minimum, maximum, average, or frequency. An average requires both total and count; it is undefined when the count is zero unless the procedure explicitly handles that case.
Retrieval prompt: explain why “sum/count” is not safe until you know the count is non-zero.
Week 4 — correctness and interpretation
An algorithm can run without errors and still answer the wrong question. Correctness means its result matches its specification; validation asks whether the input and assumptions make sense. Translate the final variable back into a sentence about the dataset. If you cannot state what
X means in ordinary language, do not trust the output.When comparing two groups, define the comparison rule first: greater count, greater sum, or greater average are different claims. Build tiny counterexamples to test whether a procedure distinguishes them.
The procedure taxonomy
| Term | What it means | Question to ask yourself |
|---|---|---|
| specification | A statement of the required input, output, and constraints. | “What exact claim must this process produce?” |
| record | One structured observation in a dataset. | “Which fields belong to one unit?” |
| attribute / field | A named property of a record. | “What is its type, unit, and permitted range?” |
| state | All values that may change while a procedure runs. | “What must I remember from earlier records?” |
| initialization | The state before the first record is processed. | “Does the initial value mean something true for zero records?” |
| invariant | A statement that stays true after every completed iteration. | “What does this variable mean after k records?” |
| precondition | What must be true before the procedure begins. | “Can the data be empty, malformed, or missing a field?” |
| postcondition | What will be true when the procedure finishes. | “How do I recognise a correct final result?” |
| counterexample | A small valid input that disproves a claim. | “Can I break this rule with three records?” |
A reliable reading order for pseudocode
Do not start by tracing every line. Read a procedure in four passes:
- Name the entities. Identify records, fields, and the final quantity requested.
- Mark the state. Circle counters, accumulators, flags, and extrema. Give each an English meaning.
- Find the filter. A branch usually decides which records can affect one of those state variables.
- Prove the finish. Ask what happens for no qualifying records, one qualifying record, and the final record.
Original worked example: qualifying average
Imagine records with fields
section and score. We want the mean score for records in section B.texttotal ← 0 count ← 0 for each record r: if r.section = 'B': total ← total + r.score count ← count + 1 if count = 0: report “no qualifying records” else: report total / count
The essential idea is the invariant: after examining any first
k records, total is the sum of the section-B scores among them and count is how many such scores exist. The zero check is not decoration; average is undefined when there are no qualifying records.Trace the state, not only the output
Loading Visualizer...
Change the threshold, then process one record at a time. Before pressing Process next, predict whether the row will change
total, count, both, or neither. The invariant must remain true after a rejected record too: rejected data does not disappear from the traversal; it simply does not contribute to the qualifying aggregate.Original retrieval task: Set the threshold to 60. Which records qualify? State the final average in a full sentence that includes the filter, then lower the threshold to 50 and explain which state update caused the change.
Common confusions, untangled
- A counter is not an accumulator. A counter measures how many; an accumulator combines values. An average needs both.
- A condition is not a result.
score > 50filters records; it does not itself calculate a pass rate. - Traversal is not correctness. Visiting every record once can still be wrong if the update is attached to the wrong branch.
- A variable name is not an explanation.
xis only meaningful when you can complete the sentence “after k records, x equals …”. - A plausible output is not validation. Test deliberately awkward data: empty lists, ties, a negative value when allowed, and a record at an exact threshold.
Method cards for the four weeks
Week 1 — model before procedure
Write a miniature data dictionary: field name, type, example, and whether it can be missing. This prevents comparing a label as though it were a number or averaging the wrong unit.
Week 2 — branch as a question
Say the branch in English: “Does this record qualify?” If you cannot say it in one sentence, the predicate is probably mixing two different decisions.
Week 3 — trace as evidence
Use a table with columns for record number, relevant field values, predicate outcome, and every state variable. Do not skip the state after a rejected record; that row shows why the filter is safe.
Week 4 — test the specification
Create one tiny dataset that should satisfy the claim, one that should not, and one boundary dataset. If a procedure cannot survive tiny inputs, a larger dataset only hides the bug.
The state ledger — a compact proof tool
Every state variable should have a sentence attached to it. Before a traversal, write the sentence for zero processed records; after each row, check whether the sentence still holds.
| State kind | Typical initial value | Invariant wording | Common failure |
|---|---|---|---|
| counter | 0 | “number of qualifying records seen so far” | incrementing for every record rather than only qualifying records |
| total | 0 | “sum of qualifying values seen so far” | adding before applying the filter |
| minimum | first valid value or a sentinel | “smallest qualifying value seen so far” | using a sentinel that can be a valid data value |
| flag | False | “whether a matching record has appeared” | resetting it on a later non-match |
| frequency map | empty mapping | “count per category among processed records” | confusing a category label with its current count |
This vocabulary separates a procedure’s mechanics (assignments and branches) from its meaning (the proposition each variable represents). If the meaning cannot be stated, a trace may be arithmetically tidy and still answer the wrong question.
A worked counterexample: total is not average
Suppose group A has scores
10, 10 and group B has score 15. A procedure selecting the group with the larger total chooses A (20 > 15); a procedure selecting the group with the larger average chooses B (15 > 10). Neither answer is universally right. The specification must decide whether group size should matter. This is the cleanest way to detect a hidden ambiguity in a dataset question.Original retrieval lab
Loading Visualizer...
- Write the invariant for a traversal that counts records whose
statusequals"active". - Given an empty dataset, identify which of count, sum, minimum, and average can be reported without a special policy. Explain why.
- A procedure increments
passedwhenscore >= 50but incrementsseenfor every record. What exactly doespassed / seenrepresent? When would it be misleading? - Make a three-record counterexample showing why “first maximum found” and “last maximum found” are different specifications when ties exist.
For each answer, include a one-line data dictionary: field name, type, and one valid example. It prevents a surprising number of tracing mistakes.
Four retrieval checks
- Give a precise invariant for a procedure that finds the minimum qualifying price.
- Why does changing
if count = 0to a division-first approach create a failure mode? - Construct two three-record datasets where “largest total” and “largest average” name different groups.
- State a precondition and postcondition for a procedure that returns the number of duplicate IDs.