Skip to content

2.1.1 Computational thinking

GCSE · Paper 2 · Computational thinking, algorithms and programming · Section 2.1 · 17 flashcards · 10 practice questions

Questions

2.1.1 Computational thinking

Before you write any code, you need to understand the problem and plan how to solve it. Computational thinking is a set of habits for doing that. There are three you need to know: abstraction, decomposition and algorithmic thinking.

Key Point
- Abstraction: leave out the details you do not need, so you can focus on the ones you do.
- Decomposition: break a big problem into smaller problems that are easier to solve.
- Algorithmic thinking: work out the exact, ordered steps that solve the problem.

We will use one made-up problem throughout: Riverside Adventure Park wants a program to sell tickets and print a receipt.

Abstraction

Definition
Abstraction is removing details that are not needed, so that only the important features of the problem are left.

Think of a map of a bus network. It does not show the shape of every building or every tree. It shows stops, routes and where they join. That is all a traveller needs, so the detail is removed. The map is an abstraction of the real town.

Abstraction in the park

To sell a ticket, the program needs the visitor's age (to find the price) and how many tickets they want. It does not need the visitor's eye colour, favourite ride or shoe size. We leave these out. We say these details are *not relevant*.

Abstraction is also used when we choose what to show on screen. The ticket machine screen shows a few buttons and prices. It hides how the price is worked out and how the receipt is made.

Why abstraction helps

  • •
    The problem is simpler, so it is easier to understand and to solve.
  • •
    The program is smaller and runs faster because it holds only the data it needs.
  • •
    Programmers can reuse a solution for other similar problems, because it is not tied to extra detail.
  • •
    A user is not confused by information they do not need.
Remember
Abstraction is removing detail. It is not about making a problem harder. A good abstraction keeps everything needed to solve the problem and nothing more.

Decomposition

Definition
Decomposition is breaking a large, complex problem into smaller sub-problems. Each sub-problem can be solved separately and then the parts are put together.

Decomposition in the park

"Build the ticket system" is too big to start. Break it into parts:

  • 1.
    Ask the visitor for their age and how many tickets.
  • 2.
    Work out the price of each ticket.
  • 3.
    Work out the total.
  • 4.
    Print the receipt.
Some of these could be broken down again. "Work out the price" becomes: decide the age band, then find the price for that band. Keep breaking the problem down until every part is small enough to write as a few lines of code.

Why decomposition helps

  • •
    Small parts are easier to understand, write and test than one huge program.
  • •
    Different programmers can work on different parts at the same time, so the work is done faster.
  • •
    Parts can be reused. A "work out the price" part can also be used by the online booking page.
  • •
    If something goes wrong, you only need to look at the part that fails.
In a program, a sub-problem often becomes a subroutine: a procedure or a function. Here the "work out the price" part is a function:
pseudocode
function ticketPrice(age)
    if age < 5 then
        price = 0
    elseif age < 16 then
        price = 4
    else
        price = 8
    endif
    return price
endfunction

The main program then uses the function:

pseudocode
total = 0
for i = 1 to 3
    age = int(input("Enter age"))
    total = total + ticketPrice(age)
next i
print("Total: " + str(total))
Worked Example
Trace the main program when the three ages entered are 3, 10 and 30.
iageticketPrice(age)total
1300
21044
330812
Output: Total: 12

Algorithmic thinking

Definition
Algorithmic thinking is working out a precise set of steps, in the right order, that solves a problem. The steps must be clear enough that someone else (or a computer) could follow them without guessing.

To think algorithmically, ask these questions about the problem:

  • •
    What are the inputs? (age, number of tickets)
  • •
    What are the outputs? (the total cost, a receipt)
  • •
    What processing is needed to turn the inputs into outputs? (look up the price, multiply, add)
  • •
    What is the order of the steps?
  • •
    Do any steps need a decision (selection)? Do any steps need to be repeated (iteration)?
Almost every algorithm uses three building blocks:
Building blockMeaningExample in the park
SequenceSteps in a set orderAsk age, then find price, then print
SelectionA choice based on a conditionIf the age is under 5, the ticket is free
IterationRepeating stepsRepeat for every ticket in the group

Refining a problem

Computational thinking is rarely done in one go. You start with a broad outline and refine it, adding more detail each time, until each step can be written in code.

Worked Example
First outline:
1. Get the tickets.
2. Work out the cost.
3. Print the receipt.

Refined step 2:
2a. Set total to 0.
2b. For each ticket, ask for the age.
2c. Find the price for that age.
2d. Add the price to the total.

Step 2c can be refined again into the age bands: under 5 is free, 5 to 15 costs 4, 16 or over costs 8. Now each step is small enough to code.

Using the three together

On a real problem, you use all three. For the park program:

  • 1.
    Abstraction: decide that only the age and the number of tickets matter.
  • 2.
    Decomposition: split the job into input, price, total and receipt.
  • 3.
    Algorithmic thinking: write the exact steps, with a loop for each ticket and a selection for each age band.
Pros & Cons
AbstractionDecompositionAlgorithmic thinking
AsksWhat can I leave out?How can I split this up?What are the exact steps?
ResultA simpler problemSmaller problemsA step-by-step solution
Warning
Do not mix up the three. If you are asked to give an example of decomposition, show the problem being split into parts. Removing detail is abstraction.

Exam technique

  • •
    State or give: a short fact. "State what is meant by abstraction." Say that detail not needed is removed.
  • •
    Describe: say what the idea is and give a short example from the scenario. Do not just repeat the scenario.
  • •
    Explain: give a reason. "Decomposition helps because each part is smaller and can be tested on its own."
  • •
    Identify (which technique): look for the clue. Leaving out detail is abstraction. Splitting into parts is decomposition. A list of ordered steps is algorithmic thinking.
  • •
    In longer questions, use the real names from the scenario (the inputs, outputs and parts) rather than general words.
  • •
    For code questions, trace carefully. Write each variable in a trace table and update it line by line.
  • •
    Write any code in the exam reference language, with lower-case keywords, endif, next i and == for comparisons.