KS3National Curriculum Y8.2 24 min read 10 question quiz 18 exam marks

Computational Thinking

The four techniques that let you solve problems the way a computer scientist does, plus flowcharts and pseudocode for planning before you code.

The four techniques

1. Decomposition

Breaking a big problem into smaller problems that are easier to solve.

Planning a school trip decomposes into: choose a destination, book transport, collect permission slips, arrange staff, plan the timetable, handle payments.

Each of those is small enough to actually do.

2. Abstraction

Removing detail that does not matter, so you can focus on what does.

A map of the school for a fire drill needs the rooms, corridors and exits. It does not need the colour of the walls, where the sockets are, or what is on the noticeboards.

The skill is deciding what to leave out. Detail that is irrelevant for one problem may be essential for another.

3. Pattern recognition

Spotting things that are the same or similar, so a solution can be reused.

If you need to calculate the area of six different rectangles, you notice they all follow width x height and write one method rather than six.

4. Algorithmic thinking

Working out the steps needed, in the right order.

How they fit together

Decompose the problem, abstract away what does not matter, look for patterns you can reuse, then write the algorithm.

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.

Flowcharts

A flowchart shows an algorithm as a diagram.

SymbolShapeUse
TerminalRounded rectangleStart and Stop
ProcessRectangleA calculation or action
Input or outputParallelogramGetting data in or showing results
DecisionDiamondA question with Yes and No branches
ArrowArrowDirection of flow

Rules

  • Every flowchart starts with Start and ends with Stop
  • A decision diamond always has exactly two labelled exits
  • Arrows show the direction, and a loop is an arrow going back up

Example: is a number even?

Start Input number Is number MOD 2 = 0? Yes -> Output "Even" No -> Output "Odd" Stop

Label both branches

An unlabelled diamond means the reader cannot tell which way is yes. It is the most common mistake in flowchart questions.

Flowchart symbols, and a worked exampleThe standard flowchart symbols on the left. A terminal, a rounded shape, marks where the program starts and stops. A parallelogram is input or output, data coming in or being shown. A rectangle is a process, a calculation or an action. A diamond is a decision: a question with two exits, Yes and No. Arrows are flow lines that show the order. On the right is a worked example. The flowchart starts, inputs an age, then asks whether age is less than 16. If yes the price is set to 5, and if no it is set to 8. Both routes join up again, the price is output, and the chart stops. The same logic is written as code in a small box beside it.The symbolsStartStart / Stopwhere it begins and endsINPUTInput / Outputdata in, or shown outx = x + 1Processa calculation or an actionx > 5 ?Decisiona question with two exitsflow line: the order1Example: a ticket priceStartINPUT ageage < 16 ?YesNoprice = 5price = 8OUTPUT priceStop23age = input()if age < 16:  price = 5else:  price = 8print(price)the same thingas code
  1. Each shape has one meaning: terminals start and stop, parallelograms are input or output, rectangles are processes, diamonds are decisions.
  2. Flow lines show the order, and every chart starts and stops with a terminal.
  3. A decision has two exits, labelled Yes and No, and the two routes join up again.
Use the right shape for the job, label every decision exit, and let every route reach the end.
One algorithm as a flowchart, as Python and as pseudocode, with matching steps in matching coloursThe same algorithm written three ways. The flowchart starts, inputs an age, then reaches a decision diamond that asks whether age is greater than or equal to 18. If yes it outputs Adult, if no it outputs Child, and both paths join and reach the end. The Python code has the same steps: age equals int of input, if age is at least 18 print Adult, else print Child. The pseudocode is the same again, ending with endif. The input is coloured blue, the decision yellow, and the two outputs green and red in all three versions, so each step can be matched across them. Rounded ovals mean start and end, slanted boxes mean input and output, and a diamond means a decision.The flowchart1Startinput ageage >= 18 ?yesnooutput "Adult"output "Child"Endage.pyage = int(input("Age? "))if age >= 18:    print("Adult")else:    print("Child")2the same, in pseudocodeage = input("Age? ")if age >= 18 then    print("Adult")else    print("Child")endif3input, outputdecisionstart, endsame colour = same step, in all three
  1. The flowchart: ovals for start and end, slanted boxes for input and output, a diamond for a decision with a yes branch and a no branch.
  2. The Python version has the same steps, matched by colour.
  3. The pseudocode is the same algorithm again. Only the notation changes.
A flowchart, pseudocode and a program are three ways to write one algorithm. Practise moving between them.

Pseudocode and testing

Pseudocode describes an algorithm in plain, structured English. It is not a real language, so it will not run, but it lets you plan the logic without worrying about syntax.

OCR reference language
total = 0
for i = 1 to 5
    number = input("Enter a number")
    total = total + number
next i
average = total / 5
print("The average is " + average)

Why plan first

  • Mistakes in logic are far cheaper to fix on paper than in code
  • You can show your plan to someone else and get feedback quickly
  • The same plan works in any programming language
  • Writing the plan often reveals a step you had forgotten

Trace tables

A trace table shows the value of every variable at every step, which is how you check an algorithm actually works.

For total = 0 then for i = 1 to 3: total = total + i:

itotal
11
23
36

Testing

Choose test data of three kinds:

  • Normal: a typical value that should work, such as 25 for an age
  • Boundary: right at the edge of what is allowed, such as 0 and 120
  • Erroneous: something that should be rejected, such as "hello" or -5

Boundary data is the most useful, because that is exactly where mistakes hide.

Trace table trainer

Fill in a trace table row by row and have it marked as you type. This tool needs JavaScript, so turn it on to use it. Everything you need to answer the exam question is explained in the text above.

A trace table for a loop that adds 1, 2 and 3A short program sets total to 0, then loops for i from 1 to 3 adding i to total, then prints total. Beside it is its trace table, with one column for the line number, one for i, one for total and one for the output. Line 1 sets total to 0. Line 2 sets i to 1, line 3 makes total 1. Line 2 sets i to 2, line 3 makes total 3. Line 2 sets i to 3, line 3 makes total 6. Line 4 prints 6, so the output column of the last row holds 6. The method: take one line at a time, give each variable its own column and the output one too, write a new row each time a value changes, and read the answer from the last row.total.py1total = 02for i in range(1, 4):3    total = total + i4print(total)1How to trace2Take one line at a timeand do exactly what it saysOne column per variableand one for the outputWrite a new row each timea value changes, never overwriteCheck the last rowit is the answer the program givesThe trace table3lineitotaloutput10210311221323233336436646 is printed: 1 + 2 + 3
  1. Run the program by hand, one line at a time. Line 3 is the one that repeats.
  2. Follow four rules: one line at a time, one column per variable, a new row for each change, and check the last row.
  3. Each time the loop runs, i goes up by one and total grows: 0, 1, 3, 6.
  4. The output is written when print runs. Here it is 6.
A trace table shows exactly what the program does, one step at a time. It is how you find a logic error.

Key terms you must be able to define

Decomposition
Breaking a large problem into smaller problems that are easier to solve.
Abstraction
Removing detail that is not needed so you can focus on what matters.
Pattern recognition
Spotting similarities between problems so that a solution can be reused.
Algorithm
A set of step by step instructions in the correct order for solving a problem.
Flowchart
A diagram showing an algorithm using standard symbols joined by arrows.
Pseudocode
A plain English description of an algorithm, used for planning before coding.
Trace table
A table showing the value of each variable at every step of an algorithm.
Boundary data
Test data at the very edge of what is acceptable, where errors are most likely.

Flashcards

Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.

DefineDecomposition
AnswerBreaking a large problem into smaller problems that are easier to solve.
DefineAbstraction
AnswerRemoving detail that is not needed so you can focus on what matters.
DefinePattern recognition
AnswerSpotting similarities between problems so that a solution can be reused.
DefineAlgorithm
AnswerA set of step by step instructions in the correct order for solving a problem.
DefineFlowchart
AnswerA diagram showing an algorithm using standard symbols joined by arrows.
DefinePseudocode
AnswerA plain English description of an algorithm, used for planning before coding.
DefineTrace table
AnswerA table showing the value of each variable at every step of an algorithm.
DefineBoundary data
AnswerTest data at the very edge of what is acceptable, where errors are most likely.

Reach the top grade on this topic

The top level here comes from applying the techniques to a specific problem, not defining them.

Use the words from the question. If the problem is about a vending machine, your decomposition should mention accepting coins, checking stock and dispensing the product, not generic phrases.

Justify what abstraction removes. Say what you took out and why it does not matter for this particular problem.

Complete every row of a trace table. Even when you can see the answer, the working is what earns credit.

  • Decompose any described problem into at least four sensible sub problems
  • Draw a flowchart with a decision and a loop, with both branches labelled
  • Complete a trace table for a loop without skipping iterations
  • Choose normal, boundary and erroneous test data for a given range

Mistakes that cost marks here

Avoid these
  • Confusing decomposition with abstraction. Decomposition splits the problem up, abstraction removes detail.
  • Using the wrong flowchart symbol, particularly a rectangle where a diamond is needed.
  • Forgetting to label the yes and no branches of a decision.
  • Filling in only the last row of a trace table.
  • Choosing test data that is nowhere near the boundary.
Fun fact

The word algorithm comes from the name of a Persian mathematician, al-Khwarizmi, who died around the year 850. His book on solving equations also gave us the word algebra.

Knowledge check

0 of 10 answered
1What is decomposition?
2Which flowchart symbol is used for a decision?
3For an age field accepting 11 to 18, which is boundary test data?
4Noticing that six different shapes all need the same area formula is an example of:
5What is pseudocode used for?
6A fire escape map leaves out the colour of the walls. This is an example of:
7What does a trace table show?
8Which is erroneous test data for a field that accepts a whole number between 1 and 10?
9How many exits does a decision diamond have?
10Why plan an algorithm before writing code?
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.

18 marks
1State what is meant by decomposition and abstraction.2 marks
State

Mark scheme0 / 2
  • LDecomposition is breaking a problem into smaller parts
  • LAbstraction is removing detail that is not needed
Model answer

Decomposition means breaking a large, complex problem down into smaller sub problems, each of which is easier to understand and solve on its own. Abstraction means removing or hiding detail that is not relevant to the problem you are solving, so that you can concentrate only on what actually matters.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2A school wants a program to record how many students take a packed lunch each day. Describe how decomposition could be used to plan this program.4 marks
Describe

Mark scheme0 / 4
  • LThe problem is broken into smaller sub problems
  • LFirst sub problem such as entering the class name or date
  • LSecond sub problem such as counting or storing the numbers
  • LThird sub problem such as displaying or saving a report
Model answer

The overall problem would be broken into several smaller sub problems that can each be solved separately. One sub problem is collecting the input: asking for the date and the class, and entering how many students in that class have a packed lunch. A second is validating and storing that data, checking the number entered is sensible and saving it so it is still there tomorrow. A third is calculating totals, adding up the numbers across all the classes to get a daily figure. A fourth is producing output, displaying the daily total on screen and perhaps saving a weekly summary to a file. Each of these parts is small enough to write and test on its own, and they can then be joined together into the finished program.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3Complete a trace table for this algorithm: total = 0, then for i = 1 to 4, total = total + (i * 2), next i. State the final value of total.4 marks
Complete

Mark scheme0 / 4
  • LAfter i = 1 total is 2
  • LAfter i = 2 total is 6
  • LAfter i = 3 total is 12
  • LFinal value of total is 20
Model answer

When i is 1, i times 2 is 2, so total becomes 0 plus 2 which is 2. When i is 2, i times 2 is 4, so total becomes 2 plus 4 which is 6. When i is 3, i times 2 is 6, so total becomes 6 plus 6 which is 12. When i is 4, i times 2 is 8, so total becomes 12 plus 8 which is 20. The final value of total is therefore 20.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4Describe the purpose of the diamond and the parallelogram symbols in a flowchart.2 marks
Describe

Mark scheme0 / 2
  • LThe diamond represents a decision with two labelled branches
  • LThe parallelogram represents input or output
Model answer

The diamond represents a decision. It contains a question with a true or false answer and always has exactly two exits, one labelled Yes and one labelled No, so the flow of the algorithm splits depending on the answer. The parallelogram represents input or output, meaning either data being entered into the system, such as a user typing a number, or results being displayed, such as a message shown on screen.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5A program accepts a mark between 0 and 100. Give one example each of normal, boundary and erroneous test data, and explain what each tests.6 marks
Give

Mark scheme0 / 6
  • LNormal data such as 57
  • LExplains that normal data checks the program works with a typical value
  • LBoundary data such as 0 or 100
  • LExplains that boundary data tests the exact edge of the allowed range
  • LErroneous data such as the word hello
  • LExplains that erroneous data checks the program rejects the wrong type without crashing
Model answer

Normal test data would be a mark of 57. This is a typical value well inside the allowed range, and it tests that the program accepts and processes ordinary input correctly. Boundary test data would be 0 and 100, and also 101, because these sit exactly at the edge of what is allowed. Boundary data is the most valuable kind, since the difference between a condition written as less than 100 and one written as less than or equal to 100 only shows up at exactly that value, and off by one errors are extremely common. Erroneous test data would be entering the word hello. This is the wrong type of data entirely and should never be accepted, so the test checks that the program rejects it with a helpful message rather than crashing when it tries to treat text as a number.

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