A-Level Computer Science / Unit 9: Computational Thinking and Algorithm Design

9.2.1 From a Problem to an Algorithm

πŸ”’ Lesson slides are available to signed-in users. Sign in

9.2.1 From a Problem to an Algorithm

An algorithm is designed by transforming a problem description into a clear sequence of steps. Before writing code, the problem must be understood and the solution planned.

You should be able to:

  • Explain the difference between a problem, algorithm and program.
  • Identify input, process and output.
  • Represent algorithms using structured English, pseudocode and flowcharts.

From Problem to Algorithm

A problem describes what needs to be achieved. An algorithm describes the steps needed to solve it. A program is an implementation of the algorithm in a programming language.

StagePurpose
Problem Understand the required result.
Algorithm Design the logical steps to solve the problem.
Program Translate the algorithm into code.
Algorithm: a solution to a problem expressed as a sequence of defined steps.
Common misconception: An algorithm is not the same as code. The same algorithm can be implemented using different programming languages.

Before writing the algorithm:

  • What output is required?
  • What input data is needed?
  • What processing must happen?

Input, Process and Output

The IPO model provides a simple way to analyse a problem before designing the algorithm.

PartMeaning
Input Data provided to the algorithm.
Process Calculations, decisions or changes applied to the data.
Output The result produced by the algorithm.
Exam tip: Identify IPO before writing pseudocode. Missing inputs or outputs often lead to incomplete algorithms.

Representing Algorithms

An algorithm can be represented in different ways. The logic should remain the same even when the representation changes.

RepresentationPurpose
Structured English Uses clear command-style English to describe steps.
Pseudocode Uses programming-style notation without depending on one language.
Flowchart Uses symbols and arrows to show the flow of control.

Structured English

Structured English describes the logic of an algorithm using clear command-style statements. It should show the order of actions, decisions and repetition without using the syntax of a specific programming language.

READ NumberOfStudents

SET TotalCost TO 0

FOR each student
    READ LunchChoice

    IF LunchChoice is "Vegetarian" THEN
        ADD 5 TO TotalCost
    ELSE
        ADD 7 TO TotalCost
    END IF

NEXT student

DISPLAY TotalCost

Notice that each line represents one clear action. The algorithm can be understood without knowing Python, Java or another programming language.

Pseudocode

Pseudocode expresses the same algorithm using programming-style notation. It is more precise than structured English but is still independent of a specific programming language.

INPUT NumberOfStudents

TotalCost ← 0

FOR Count ← 1 TO NumberOfStudents

    INPUT LunchChoice

    IF LunchChoice = "Vegetarian" THEN
        TotalCost ← TotalCost + 5
    ELSE
        TotalCost ← TotalCost + 7
    ENDIF

NEXT Count

OUTPUT TotalCost

Good pseudocode uses meaningful identifiers, consistent indentation and clear control structures. The important point is that the logic is the same as the structured English version.

Flowcharts

  • Start/End β†’ beginning or end of the algorithm
  • Input/Output β†’ data entering or leaving the system
  • Process β†’ calculation or assignment
  • Decision β†’ condition with different paths
Exam tip: When converting between representations, keep the same logic. Do not add or remove steps.

Common Misconceptions

  • "The algorithm is the code."
    The algorithm is the logic; code is one possible implementation.
  • "A flowchart is just a drawing."
    A flowchart must accurately show the order of actions and decisions.
  • "Pseudocode can be written like normal English."
    Pseudocode should be precise and follow consistent conventions.
  • "More steps always mean a better algorithm."
    A good algorithm is clear and efficient, not unnecessarily complicated.
  • "Changing representation changes the algorithm."
    Structured English, pseudocode and flowcharts should describe the same solution.

Review

QuestionKey idea
What comes before programming? Understanding the problem and designing an algorithm.
What does IPO describe? How data enters, is processed and leaves the system.
Why use different representations? To communicate the same algorithm clearly in different forms.
Final exam tip: A strong algorithm answer connects the problem requirements to the steps of the solution.