Computational Thinking
Abstraction, decomposition and algorithmic thinking, explained with examples that actually show what each one does rather than just naming it.
Abstraction
Abstraction is removing unnecessary detail from a problem so you can focus on what matters.
The skill is deciding what is unnecessary. A detail that is irrelevant to one problem may be essential to another.
Example: a satnav
- Keeps: roads, junctions, distances, speed limits, one way systems
- Removes: what the buildings look like, the weather, who lives there, the colour of the road markings
None of the removed detail helps you find a route, and including it would make the problem enormous and slow.
Example: a chess program
- Keeps: the position of each piece, whose turn it is, the legal moves
- Removes: what the pieces are made of, how heavy they are, the design of the board
It makes a problem simpler and quicker to solve, and it makes the solution more general, because a program built on the essentials works for many different situations rather than one.
Say what is removed and why it does not matter. That second half is where the mark is.
- The real thing is full of detail: most of it is no use for the job in hand.
- The abstraction is a simple model that keeps only what the job needs.
- What stays: the stations, what connects to what, and the lines.
- What goes: the detail that does not help, such as houses, exact distances and street names.
Decomposition
Decomposition is breaking a large complex problem down into smaller sub problems that are easier to solve.
Each sub problem can then be solved separately, and the solutions combined.
Example: writing a quiz game
Decomposed into:
- Load the questions from a file
- Display a question and its options
- Accept and validate the user's answer
- Check whether the answer is correct
- Keep and update the score
- Move to the next question
- Display the final result
Each of these is small enough to write and test on its own.
Why decomposition helps
- Each part is easier to understand than the whole
- Parts can be worked on by different people at the same time
- Each part can be tested independently, so bugs are easier to find
- Parts can be reused in other programs, for example the validation routine
- Progress is easier to measure
Decomposition breaks a problem into smaller sub problems that are easier to solve, test and maintain, and which can be worked on separately or by different people.
- Start with the whole problem at the top.
- Split it into a few main parts.
- Keep splitting until every part is small enough to solve.
- Why bother: parts can be built in parallel, tested separately and reused.
Algorithmic thinking
Algorithmic thinking is identifying the steps needed to solve a problem, and putting them in the correct order.
It is what turns a decomposed problem into something a computer can actually run.
An algorithm must be:
- Unambiguous. Every step has exactly one meaning.
- Correctly ordered. Steps that depend on earlier results must come after them.
- Complete. No missing steps.
- Finite. It must eventually stop.
Example: making a hot drink as an algorithm
- Fill the kettle with water
- Switch the kettle on
- Put a teabag in a mug
- WAIT until the kettle boils
- Pour the water into the mug
- WAIT 3 minutes
- Remove the teabag
- Add milk if wanted
- Stir
Step 4 must come before step 5. Step 7 must come after step 6. Order is not decoration, it is the algorithm.
How the three work together
| Stage | What you do |
|---|---|
| Decomposition | Break the problem into parts |
| Abstraction | Strip each part down to what matters |
| Algorithmic thinking | Work out the ordered steps to solve each part |
Then the parts are combined into a working program.
Step 1 of 3 Decomposition: break the problem into parts small enough to solve one at a time.
- Decomposition: break a big problem into small parts you can solve one at a time.
- Abstraction: keep what matters and hide the detail you do not need.
- Pattern recognition: spot what repeats, so one solution can be reused.
- Algorithms: put the solution in clear steps that a computer, or anyone, can follow.
Key terms you must be able to define
- Computational thinking
- Approaching a problem in a way that allows a computer to solve it, using abstraction, decomposition and algorithmic thinking.
- Abstraction
- Removing unnecessary detail from a problem so that only what matters is considered.
- Decomposition
- Breaking a large problem into smaller sub problems that are easier to solve.
- Algorithmic thinking
- Identifying the individual steps needed to solve a problem and placing them in the correct order.
- Sub problem
- One of the smaller parts a problem has been broken into.
Flashcards
Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.
Reach the top grade on this topic
The trap on this topic is that the definitions are easy, so students give a definition when the question asked for an application.
Read the command word carefully. "Describe how abstraction could be used in this program" is not asking for a definition. It is asking you to name specific details that would be removed from that scenario and say why they do not matter.
Use the scenario's own words. If the question is about a train timetable app, your answer should mention platforms, departure times and station names, not generic phrases about removing detail.
Show decomposition as a numbered list. Four or five clearly separate sub problems, each of which sounds like something you could write as a subroutine.
- Apply abstraction to any given scenario, naming what is kept and what is removed
- Decompose any described program into at least five sensible sub problems
- Explain three benefits of decomposition
- Explain why the order of steps in an algorithm matters, with an example
Mistakes that cost marks here
- Defining abstraction as 'making something simpler' without saying what detail is removed or why.
- Giving decomposition sub problems that are too vague, such as 'make the game work'.
- Confusing abstraction and decomposition. Abstraction removes detail, decomposition splits the problem up.
- Answering with a definition when the question asked you to apply the idea to a scenario.
The London Underground map is one of the most famous pieces of abstraction ever made. It removes real distances, real directions and everything above ground, keeping only what a passenger needs: the order of stations and where lines meet.
Knowledge check
Exam-style questions
Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.
- LRemoving or hiding unnecessary detail
- LSo that only the information relevant to solving the problem remains
Abstraction is the process of removing or hiding detail that is not necessary for solving a particular problem, so that only the information which is actually relevant remains. This makes the problem simpler to understand and to solve, and often makes the resulting solution more widely applicable.
- LThe problem is broken into smaller sub problems
- LGives a valid sub problem such as recording vehicles entering
- LGives a second valid sub problem such as calculating the charge
- LExplains a benefit such as each part can be written and tested separately or by different people
Decomposition would be used to break the overall car park system into smaller sub problems that can each be solved on their own. For example, one sub problem would be recording vehicles entering, which involves reading the number plate and logging the arrival time and raising the barrier. A second would be calculating the charge when a vehicle leaves, which involves finding the arrival record, working out the duration and applying the tariff. Further sub problems would include processing payment, tracking how many spaces remain free, and producing reports for the owner. Breaking the problem down this way means each part is small enough to be understood fully, different programmers can work on separate parts at the same time, and each part can be tested independently so that faults are much easier to locate.
- LUnnecessary details are removed
- LGives examples of removed detail such as scenery, station architecture or the type of train
- LRetains only the relevant information such as stations, connections and journey times
Abstraction would be used to strip the real railway network down to only the information needed to find a shortest route. Details such as what the stations look like, the type of train used on each service, the scenery along the route and the number of passengers travelling would all be removed, because none of them affect which sequence of connections is quickest. What would be retained is the set of stations, which stations are directly connected to which others, and the journey time or distance for each connection. This turns a very complex real world system into a simple network of points and weighted links, which a routing algorithm can then process quickly.
- LEach smaller part is easier to understand and solve
- LParts can be developed or tested independently, or by different people
Each sub problem is much smaller than the original problem, so it is easier to understand and to solve correctly. In addition, the sub problems can be allocated to different programmers who can work on them at the same time, and each part can be tested independently, which means errors are located much more quickly than in a single large program.
- LSome steps depend on the result of earlier steps
- LIf the order is wrong the algorithm produces an incorrect result or fails
- LGives a valid example demonstrating a dependency
The order of steps matters because many steps depend on values or conditions produced by earlier steps, so carrying them out in the wrong sequence produces an incorrect result or causes the algorithm to fail completely. For example, in an algorithm that calculates the average of a set of numbers, the total must be calculated before it is divided by the count. If the division were carried out first, the program would divide an empty or partial total and produce a meaningless answer. Similarly, a program cannot validate a user's input before it has asked for that input, so the input step must come first.