Four habits, not four topics
Computational thinking is a way of approaching a problem so that a computer — or a person following instructions exactly — could solve it. It is not programming; you can do it on paper, and it is the part that decides whether the eventual program works.
The syllabus names four components, and they are used together rather than in sequence.
- Decomposition — break a large problem into smaller sub-problems, each small enough to solve on its own. "Build a school management system" is unapproachable; "record one student's attendance" is not.
- Pattern recognition — spot what the sub-problems have in common. If registering a student and registering a teacher differ only in one field, one solution can serve both.
- Abstraction — ignore the detail that does not matter for the problem at hand. A map of the bus routes leaves out every building, and is more useful for its purpose because of it.
- Algorithm design — write the sequence of steps that solves the problem, precisely enough that following them requires no judgement.
Abstraction is about what you leave out
Students often describe abstraction as "simplifying", which is close but loses the point. The skill is deciding which details are irrelevant for this problem. A city map for a driver shows one-way streets and omits contours; a map for a hiker does the opposite. Neither is a worse map — they abstract away different things.
What makes something an algorithm
Algorithm — A finite, ordered set of unambiguous instructions which, when followed, solves a problem or completes a task in a finite number of steps.
An algorithm is a finite sequence of unambiguous steps that solves a problem or performs a task. Each word in that definition is doing work, and questions test them.
Finite: it must stop. A set of instructions that loops for ever is not an algorithm. Unambiguous: each step must have exactly one interpretation — "add a little salt" fails, "add 5 grams of salt" passes. And it must have defined inputs and outputs, so you know what it needs and what it produces.
| Written as | Looks like | Best for |
|---|---|---|
| Flowchart | boxes and arrows | seeing the flow of control at a glance |
| Pseudocode | structured English | longer algorithms, and translating to code |
| Structured English | ordinary sentences, numbered | explaining to a non-programmer |
Flowcharts
A flowchart shows the order in which steps happen, using a fixed set of shapes. The shapes are part of the answer: using a rectangle where a diamond belongs loses the mark even if the logic is right.
Every flowchart has exactly one START and at least one STOP. A decision diamond has exactly two exits, labelled Yes and No, and every arrow carries an arrowhead so the direction is unambiguous.
The decision diamond is the only shape with two ways out, and both branches must be labelled. An unlabelled branch is the most common reason a correct flowchart still loses a mark.
Pseudocode
Pseudocode sits between English and a real programming language. It has no fixed standard, so the paper accepts any consistent style — but it must be structured, indented, and unambiguous.
Use keywords for the control structures, indent everything inside a block, and give variables meaningful names.
Write an algorithm, in pseudocode, that reads 10 numbers and outputs the largest.
- Read the first number and use it as the starting value for
largest.Setting largest = 0 to begin with fails if every number entered is negative — 0 would then win. Using the first actual value avoids the problem entirely. INPUT largestthenFOR count = 2 TO 10The loop runs nine more times, because the first number has already been read.INPUT numberthenIF number > largest THEN SET largest = numberCompare each new value with the best so far, and replace it only when it is bigger.NEXT countthenOUTPUT largestThe output belongs outside the loop; putting it inside would print ten times.
Read the first value as the initial largest, then compare the remaining nine, replacing when bigger.
Where the output statement goes
Inside the loop, OUTPUT largest runs on every pass and prints ten lines. Outside, it runs once with the final answer. Indentation is what shows the examiner which you meant, which is why unindented pseudocode can lose marks even when the logic is correct.
Testing an algorithm before it is code
A dry run or trace table checks an algorithm by hand. Make one column per variable, one row per pass through the loop, and write down what every variable holds at each step. Errors show up immediately, and finding them here is far cheaper than finding them after the program is written.
Choose test data deliberately: normal values that should work, boundary values at the edges of what is allowed, and erroneous values that should be rejected. An algorithm that handles only normal data is not finished.
Before you leave this chapter
- Decomposition, pattern recognition, abstraction, algorithm design.
- Abstraction means deciding which details to leave out for this particular problem.
- An algorithm must be finite and unambiguous, with defined inputs and outputs.
- Flowchart shapes are marked: rounded for start/stop, parallelogram for I/O, rectangle for process, diamond for decision.
- Trace an algorithm with a table before coding it, using normal, boundary and erroneous data.