KS4J277 2.1.1 20 min read 10 question quiz 14 exam marks

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
Why abstraction matters

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.

Abstraction is not just 'simplifying'

Say what is removed and why it does not matter. That second half is where the mark is.

Abstraction: a map that keeps only what mattersAbstraction shown with a town and a map of it. On the left is the real town, packed with houses, trees, a river, roads and cars. On the right is its abstraction, a clean map of three coloured lines, with stations as white circles and interchanges where lines cross. What stays is the stations, which connect to which, and the lines. What goes is the houses and trees, the exact distances and the street names, because none of them help you plan a journey. The same idea runs through programming: a variable name hides the memory address behind it, a function such as print hides the code inside it, and a button hides the server it talks to.The real townThe abstractionParkCentreMarketStationHillDocks12What staysthe stationswhich connect to whichthe linesWhat goeshouses and treesexact distancesstreet namesIn codescorehides memoryprint()hides its codea buttonhides the server34
  1. The real thing is full of detail: most of it is no use for the job in hand.
  2. The abstraction is a simple model that keeps only what the job needs.
  3. What stays: the stations, what connects to what, and the lines.
  4. What goes: the detail that does not help, such as houses, exact distances and street names.
Abstraction is deciding what to leave out. Say what was removed and why it was safe to remove it.

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:

  1. Load the questions from a file
  2. Display a question and its options
  3. Accept and validate the user's answer
  4. Check whether the answer is correct
  5. Keep and update the score
  6. Move to the next question
  7. 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
The exam phrasing

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.

Decomposition: breaking a quiz app into partsDecomposition drawn as a tree. The whole problem, a quiz app, sits at the top. It splits into four parts: questions, scoring, the timer and the screens. Each of those splits again into smaller jobs. Questions becomes store them, pick at random and check the answer. Scoring becomes add points and high scores. The timer becomes count down and end the round. The screens become the menu, the question screen and the results. Each small part can be solved on its own. A panel on the right gives the three reasons to do this: different people can build different parts at the same time, a fault is easy to find in a small part, and a part such as the timer can be reused in another program.A quiz appQuestionsstore thempick at randomcheck the answerScoringadd pointshigh scoresTimercount downend the roundScreensmenuquestionresultseach small part can be solved on its own123Why break it up?Build in paralleldifferent people writedifferent partsTest one parta fault is easy tofind in a small partReuse a partthe timer can serveanother game4
  1. Start with the whole problem at the top.
  2. Split it into a few main parts.
  3. Keep splitting until every part is small enough to solve.
  4. Why bother: parts can be built in parallel, tested separately and reused.
Decomposition is top-down: big problem, main parts, small jobs. Say what each small part is for.

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

  1. Fill the kettle with water
  2. Switch the kettle on
  3. Put a teabag in a mug
  4. WAIT until the kettle boils
  5. Pour the water into the mug
  6. WAIT 3 minutes
  7. Remove the teabag
  8. Add milk if wanted
  9. 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

StageWhat you do
DecompositionBreak the problem into parts
AbstractionStrip each part down to what matters
Algorithmic thinkingWork out the ordered steps to solve each part

Then the parts are combined into a working program.

Computational thinking applied to one problemComputational thinking applied to one problem, marking a class set of quizzes. Decomposition breaks it into parts: read the answers from a file, compare each one to the key, count the marks, work out a grade and write a report. Abstraction decides what matters and what does not: keep the answer given and the correct answer, ignore the pupil's handwriting, how long they took and the colour of the paper. Algorithmic thinking then writes the steps in an order a computer can follow, looping over each pupil and each question and adding one to the score whenever the answer matches the key.Problem: write a program that marks a class set of quizzesDECOMPOSITIONRead the answers from a fileCompare each one to the keyCount the marksWork out a gradeWrite a reportABSTRACTIONKeep: the answer givenKeep: the correct answerIgnore: the pupil's handwritingIgnore: how long they tookIgnore: the paper colourALGORITHMFOR each pupil score = 0 FOR each question IF answer = key THEN score = score + 1
The three pillars on a single problem. In an exam, name the pillar and then show it doing something to the problem in front of you; naming it alone rarely scores.
The four techniques of computational thinking, shown on a satnavThe four techniques of computational thinking, one card each, all using a satnav as the example. Decomposition breaks a big problem into small parts: plan a journey splits into find the roads, choose a route, estimate the time and give directions. Abstraction keeps what matters and hides the rest: a busy picture of a town, with its houses, trees, river and roads, is simplified into a clean map of coloured lines and stations. Pattern recognition spots what repeats: five small charts for Monday to Friday all show the same rush hour peak, so it can be predicted. Algorithms are clear, step by step instructions anyone could follow: find where you are, find where you want to go, pick the shortest route and give the next turn.DecompositionAbstractionPattern recognitionAlgorithmsPlan ajourneyfind the roadschoose a routeestimate the timegive directionsbreak a big problem into small partskeep what matters, hide the restMTWTFthe same peak every weekday, so we can predict it1find where you are2find where you want to go3pick the shortest route4give the next turnclear steps anyone could follow1234
  1. Decomposition: break a big problem into small parts you can solve one at a time.
  2. Abstraction: keep what matters and hide the detail you do not need.
  3. Pattern recognition: spot what repeats, so one solution can be reused.
  4. Algorithms: put the solution in clear steps that a computer, or anyone, can follow.
A real problem needs all four. Name the technique and say what it did to the problem.

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.

DefineComputational thinking
AnswerApproaching a problem in a way that allows a computer to solve it, using abstraction, decomposition and algorithmic thinking.
DefineAbstraction
AnswerRemoving unnecessary detail from a problem so that only what matters is considered.
DefineDecomposition
AnswerBreaking a large problem into smaller sub problems that are easier to solve.
DefineAlgorithmic thinking
AnswerIdentifying the individual steps needed to solve a problem and placing them in the correct order.
DefineSub problem
AnswerOne of the smaller parts a problem has been broken into.

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

Avoid these
  • 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.
Fun fact

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

0 of 10 answered
1What is abstraction?
2A programmer splits a game into separate parts for movement, scoring and collision detection. This is:
3Which detail would most sensibly be removed by abstraction in a bus timetable app?
4Which is a benefit of decomposition?
5An algorithm must be finite. This means:
6Why does the order of steps in an algorithm matter?
7A weather app ignores the historical rainfall of a region when showing today's forecast. This is an example of:
8Which of these is the best example of a sub problem from decomposing an online shop?
9Algorithmic thinking is best described as:
10Which of the three techniques is being used when a programmer decides that a chess program does not need to know what the pieces are made of?
Score 0 / 10

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.

14 marks
1Define the term abstraction.2 marks
Define

Mark scheme0 / 2
  • LRemoving or hiding unnecessary detail
  • LSo that only the information relevant to solving the problem remains
Model answer

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.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2A company is writing a program to manage a car park. Describe how decomposition could be used when developing this program.4 marks
Describe

Mark scheme0 / 4
  • 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
Model answer

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.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3Explain how abstraction would be used in a program that finds the shortest route between two railway stations.3 marks
Explain

Mark scheme0 / 3
  • 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
Model answer

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.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4State two benefits of using decomposition when developing a large program.2 marks
State

Mark scheme0 / 2
  • LEach smaller part is easier to understand and solve
  • LParts can be developed or tested independently, or by different people
Model answer

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.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5Explain why the order of the steps in an algorithm is important, using an example.3 marks
Explain

Mark scheme0 / 3
  • 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
Model answer

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.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
Machine mark 0 / 14