Learning Objectives
By the end of this lesson, you will be able to:
- Definewhat an algorithm is: a specific sequence of steps that can be followed to complete a task
- Explainthat a computer program is an implementation of an algorithm, but an algorithm is not a computer program itself
- Identifythe three main ways an algorithm can be designed: structure diagrams, flowcharts and pseudocode
- Statethe purpose of a given algorithm clearly and concisely
- Describethe individual processes involved in an algorithm step by step
- Interpretpseudocode and flowcharts and explain what they do
- Applytechniques to understand complex algorithms: looking for comments, considering context, and testing with different inputs
Key Terms
Algorithm
A specific sequence of steps that can be followed to complete a task. A precise set of rules or instructions to solve a specific problem.
Computer program
An implementation of an algorithm. The algorithm itself is not a computer program.
Structure diagram
Shows hierarchical top-down design in a visual form. Each problem is divided into sub-problems, and each sub-problem into further sub-problems.
Flowchart
A visual tool that uses shapes to represent different functions to describe an algorithm. Shows input, output, processes, decisions and repetition.
Pseudocode
A text-based tool that uses short English words and statements to describe an algorithm. More structured than English sentences but very flexible.
Purpose
A clear, concise statement of the problem the algorithm addresses and the expected outcome. Should be specific.
Processes
The individual steps or operations that the algorithm performs to achieve its purpose.
Sequence
Steps carried out one after another in order.
Selection
A decision point where the algorithm follows different paths based on a condition (IF...THEN...ELSE).
Iteration
Repetition of steps in an algorithm (loops such as FOR, WHILE, REPEAT).
Terminator symbol
The oval shape used in a flowchart to show the start or stop of an algorithm.
Input/Output symbol
The parallelogram shape used in a flowchart to show data entering or leaving the algorithm.
Process symbol
The rectangle shape used in a flowchart to show a process or action.
Decision symbol
The diamond shape used in a flowchart to show a yes/no question or condition.
1. What is an Algorithm?
Analgorithmis nothing more than aspecific sequence of stepsthat can be followed to complete a task. It is a precise set of rules or instructions to solve a specific problem or task.
Key idea
Acomputer programis animplementation of an algorithm. An algorithm isnota computer program in itself — it is the logic and steps that the program will follow.
1.1 The Sandwich Example
Making a sandwich is an everyday task that can be broken down into a sequence of steps — an algorithm. Here are the choices you might make:
1. White or brown bread?
2. Spread?
Butter or margarine?
3. Sauce?
4. Filling
Lettuce? Tomatoes? Bacon?
Each of these decisions is a step in the algorithm. Following the steps in order — with choices at each stage — produces the final sandwich. In the same way, a computer program follows an algorithm to produce a result.
Real-Life Algorithm: Making a Sandwich
- Choose white or brown bread
- Spread butter or margarine
- Add sauce
- Add filling (lettuce, tomatoes, bacon)
- Put the two slices of bread together
- Cut the sandwich (optional)
This is a sequence of steps that can be followed to complete the task of making a sandwich. It is an algorithm.
1.2 Algorithm Building Blocks
Every algorithm can be built from three fundamental building blocks:
Sequence
Steps are carried out one after another, in order.
Selection
A decision is made, and the algorithm follows different paths based on a condition.
Iteration
Steps are repeated (loops) until a condition is met.
Visual: Sequence, Selection and Iteration
This diagram shows how the three building blocks fit together in an algorithm.
How to read it:The algorithm moves from Start, through aprocess(sequence), to adecision(selection). If the answer is "No", the flow loops back to repeat the process (iteration). If "Yes", the algorithm moves to Stop.
Activity 1: Everyday Algorithms
Write a sequence of steps (an algorithm) for each of the following everyday tasks:
- Brushing your teeth
- Making a cup of tea
- Getting ready for school in the morning
For each algorithm, identify whereselection(a decision) occurs.
Example Answers:
1. Brushing your teeth:
- Pick up toothbrush
- Apply toothpaste
- Brush teeth for 2 minutes
- Rinse mouth
2. Making a cup of tea:
- Boil water
- Put tea bag in cup
- Pour water into cup
- Selection:Do you want milk? If yes, add milk.
- Selection:Do you want sugar? If yes, add sugar.
- Stir
3. Getting ready for school:
- Wake up
- Get out of bed
- Wash and dress
- Eat breakfast
- Selection:Have you packed your bag? If not, pack it.
- Leave for school
Check Your Understanding: What is an Algorithm?
1. Define the term "algorithm". [2 marks]
Answer
- [1 mark]A specific sequence of steps
- [1 mark]That can be followed to complete a task / solve a specific problem
2. Explain the relationship between an algorithm and a computer program. [3 marks]
Answer
- [1 mark]A computer program is an implementation of an algorithm
- [1 mark]The algorithm is the logic/steps; the program is the code that carries them out
- [1 mark]An algorithm is not a computer program in itself — it can exist without being written in code
3. Name the three fundamental building blocks that every algorithm can be built from. [3 marks]
Answer
- [1 mark]Sequence
- [1 mark]Selection
- [1 mark]Iteration
4. Give an example of an everyday task that can be represented as an algorithm, and list its steps. [3 marks]
Answer
[1 mark]Any suitable everyday task (e.g. making a sandwich, crossing the road, getting ready for school).
[2 marks]A correct sequence of at least three steps in the correct order.
Example:Making a sandwich: (1) choose bread, (2) add spread, (3) add filling, (4) close the sandwich.
5. Explain the difference between selection and iteration in an algorithm. [4 marks]
Answer
- [2 marks]Selectionis a decision point where the algorithm chooses between different paths based on a condition (e.g. IF...THEN...ELSE)
- [2 marks]Iterationis the repetition of steps in a loop (e.g. FOR, WHILE, REPEAT) until a condition is met
6. Why is it important for an algorithm to be a "specific sequence of steps"? [2 marks]
Answer
- [1 mark]So the task is completed correctly and consistently every time
- [1 mark]If steps are missed or carried out in the wrong order, the algorithm will not produce the correct result
2. Three Ways to Design an Algorithm
There are three main ways to design an algorithm. In the exam you need to be able tocreate, interpret, correct and refinealgorithms using these methods.
Structure diagrams
Hierarchical top-down design in a visual form
Flowcharts
Visual tool using shapes to represent functions
Pseudocode
Text-based tool using short English statements
2.1 Structure Diagrams
Structure diagrams showhierarchical top-down designin a visual form. Each problem is divided into sub-problems and each sub-problem is divided into further sub-problems. At each level the problem is broken down into more detailed tasks that can be implemented using asingle subroutine.
Example: Mobile Phone Structure Diagram
A structure diagram for a mobile application shows how the top-level "Mobile phone" is broken down:
The "Send voice" branch is broken down further into "Capture voice", "Convert to digital" and "Transmit on network" — each of these would be implemented as a single subroutine.
2.2 Flowcharts
Flowcharts are avisual toolthat uses shapes to represent different functions to describe an algorithm. They show the data that isinputandoutput, theprocessesthat take place and anydecisionsorrepetition. Lines are used to show theflow of control.
Example: Age Check for a Casino Site
A casino would like a program that asks users to enter an age. If they are 18 or over they can enter the site; if not, they are given a suitable message.
Refinement:The casino would like the algorithm refined so that the user also enters their first name and this is used to greet the user when they access the site. This means adding an extraINPUT Namestep and changing the welcome output to include the name.
2.3 Pseudocode
Pseudocode is atext-basedtool that uses short English words/statements to describe an algorithm. Pseudocode ismore structured than writing sentences in Englishbut is very flexible.
Examiner Tips and Tricks
Pseudocode isnot real code— don't use syntax likeprint()orinput()with brackets. Stick to simple statements likeINPUT AgeandOUTPUT "Welcome". Adding actual language syntax can lose you marks.
Example: Age Check Pseudocode
Refined Version (also asks for name)
Examiner Tips and Tricks
If the question asks you to write an algorithm,default to pseudocode. Use flowcharts only when asked or when visual logic helps. Examiners reward clarity, not decoration.
Same Algorithm, Three Representations
The pseudocode and flowchart above both represent thesame algorithm. Implementing this algorithm as a solution will produce a computer program that asks the user to input two numbers and outputs which of the two is larger.
- Structure diagram— shows the hierarchy of sub-problems
- Flowchart— visual, using shapes and arrows
- Pseudocode— text-based, using simple statements
Activity 2: From Flowchart to Pseudocode
The flowchart below asks the user for two numbers and outputs the larger one.
- Write the CIE pseudocode for this algorithm.
- Describe what the algorithm does in one sentence.
Solution:
- CIE pseudocode:INPUT number1INPUT number2IF number1 > number2 THENOUTPUT "The largest number is ", number1ELSEOUTPUT "The largest number is ", number2ENDIF
- Description:The algorithm asks the user to input two numbers and then outputs the larger of the two numbers.
Check Your Understanding: Three Ways to Design an Algorithm
1. Name the three main ways to design an algorithm. [3 marks]
Answer
- [1 mark]Structure diagrams
- [1 mark]Flowcharts
- [1 mark]Pseudocode
2. What is a structure diagram and what does it show? [3 marks]
Answer
- [1 mark]A structure diagram shows hierarchical top-down design in a visual form
- [1 mark]Each problem is divided into sub-problems and each sub-problem into further sub-problems
- [1 mark]At each level the problem is broken down into more detailed tasks that can be implemented using a single subroutine
3. Describe the four main shapes used in a flowchart and what each represents. [4 marks]
Answer
- [1 mark]Oval (terminator) — start or stop
- [1 mark]Parallelogram (input/output) — data entering or leaving the algorithm
- [1 mark]Rectangle (process) — a process or action
- [1 mark]Diamond (decision) — a yes/no question or condition
4. What is pseudocode and why is it useful? [3 marks]
Answer
- [1 mark]Pseudocode is a text-based tool that uses short English words/statements to describe an algorithm
- [1 mark]It is more structured than writing sentences in English but is very flexible
- [1 mark]It is not real code — it does not use the syntax of any particular programming language, so it can be translated into any language later
5. Write CIE pseudocode for a program that asks for the user's age. If the age is 18 or over, it outputs "Welcome to the site". Otherwise, it outputs "Sorry, this site is for users 18 and over". [5 marks]
Answer
Marking:INPUT statement (1), correct IF condition (1), correct THEN output (1), correct ELSE output (1), ENDIF (1).
6. Give one reason why pseudocode is preferred over a flowchart in an exam when asked to "write an algorithm". [2 marks]
Answer
- [1 mark]Pseudocode is quicker to write and easier to edit than drawing a flowchart
- [1 mark]Examiners reward clarity — pseudocode uses simple statements that are easy to mark, whereas a messy flowchart can lose marks for unclear symbols or arrows
3. Explaining the Purpose of an Algorithm
In the exam, you will need to be able toexplain the purpose of a specific algorithm. The algorithm might be presented as aflowchartor aspseudocode.
3.1 Stating the Purpose
An algorithm is a step-by-step procedure or formula for solving a problem or completing a task. Algorithms are designed to achieve a specific objective or solve a particular problem efficiently and accurately.
How to state the purpose
When stating the purpose of an algorithm, it is essential to clearly define:
- What problem it addresses
- What the expected outcome is
The purpose should bespecific and concise, outlining the problem-solving goal the algorithm aims to achieve.
Example of Stating the Purpose
"The purpose of the algorithm is to sort a list of integers in ascending order."
In this example, the purpose is clear: the algorithm aims to arrange a given list of integers in ascending order, ensuring that the numbers are sorted from smallest to largest.
3.2 Describing the Processes
When describing the processes involved in an algorithm, it is crucial to detail theindividual steps or operationsthat the algorithm performs. This description should provide a clear and precise explanation of how the algorithm achieves its purpose. It often involves:
- Breaking down the problem into smaller sub-problems
- Defining the sequence of steps to be executed
- Specifying any conditions or loops involved
Example: Factorial of a Non-Negative Integer
Consider the problem of finding the factorial of a non-negative integer. The factorial of a number is the product of all positive integers from 1 up to that number.
Algorithm Purpose:"The purpose of the algorithm is to calculate the factorial of a non-negative integer."
Algorithm Processes:
- Input:Receive a non-negative integer n as input.
- Initialization:Set factorial to 1 (initial factorial value).
- Loop:For each integer i from 1 to n, repeat steps 4 and 5.
- Multiplication:Multiply factorial by i.
- Update Factorial:Update factorial with the result of the multiplication.
- Output:Return the calculated factorial as the output.
This description breaks down the algorithm into its individual processes, clearly outlining the steps involved in calculating the factorial of a non-negative integer.
3.3 How Do You Explain an Algorithm?
A well-designed algorithm should be able to be interpreted by a new user, and they should be able to explain what it does.
Algorithms can be written using flowcharts, pseudocode or high-level programming language code such as Python. The purpose of an algorithm is to solve a problem. If a user does not know the goal of the algorithm, then following the algorithm instructions should make its purpose clear.
If the algorithm is complex, additional ways to understand it:
- Look for comments in the code
- Consider the context of where the algorithm is being used
- Test the algorithm with different inputs
Example: What Does This Algorithm Do?
Purpose
The purpose of the algorithm is to add ten user-entered numbers together and output the total.
The processes are:
- Initializing three variables (Count, Number, Total)
- Inputting a user number
- Adding to two variables (Total, Count)
- Repeating nine more times
- Outputting the final Total value
Activity 3: Explain the Purpose
Look at the following pseudocode algorithm:
- State the purpose of the algorithm in one sentence.
- List the processes involved in the algorithm.
Solution:
- Purpose:The purpose of the algorithm is to input five scores, calculate their average, and output the average.
- Processes:
- Initialising Total and Count to 0
- Repeating the following five times: inputting a score, adding it to Total, and incrementing Count
- Calculating the average by dividing Total by 5
- Outputting the average
Check Your Understanding: Explaining the Purpose
1. What two things should a clear statement of purpose include? [2 marks]
Answer
- [1 mark]What problem the algorithm addresses
- [1 mark]What the expected outcome is
2. Why is it important that the purpose of an algorithm is specific and concise? [2 marks]
Answer
- [1 mark]So that anyone reading it can understand exactly what the algorithm is for, without confusion
- [1 mark]A precise statement of purpose makes it easier to check whether the algorithm actually achieves its goal
3. State the purpose of the following algorithm in one sentence: [2 marks]
Total ← 0
FOR i ← 1 TO 10
INPUT Number
Total ← Total + Number
NEXT i
OUTPUT Total
Answer
- [2 marks]The purpose of the algorithm is to input ten numbers, add them together, and output the total.
4. Describe three ways you could understand the purpose of a complex algorithm. [3 marks]
Answer
- [1 mark]Look for comments in the code
- [1 mark]Consider the context of where the algorithm is being used
- [1 mark]Test the algorithm with different inputs
5. Explain why "following the algorithm instructions should make its purpose clear". [2 marks]
Answer
- [1 mark]Because the steps in the algorithm show exactly what data is input, what processing happens, and what output is produced
- [1 mark]By tracing through the steps, a reader can work out what problem the algorithm is solving
6. The following algorithm uses a REPEAT...UNTIL loop. What is its purpose? [2 marks]
Count ← 0
Password ← ""
REPEAT
OUTPUT "Enter password: "
INPUT Password
Count ← Count + 1
UNTIL Password = "secret" OR Count = 3
Answer
- [2 marks]The purpose of the algorithm is to ask the user for a password. It gives the user up to three attempts to enter the correct password ("secret"). The loop stops when the correct password is entered or after three attempts.
4. Worked Example: Grade Assignment Algorithm
The pseudocode algorithm shown has been written by a teacher to enter marks for the students in her class and then to apply some simple processing.
Describe what happens in this algorithm.
Show Mark Scheme
Answer (any 3 of):
- Inputted marks are stored in the arrayScore[]
- Marks are then checked against a range of boundaries
- A matching grade is assigned to each mark that has been input
- The grade is then stored in the arrayGrade[]
- At the same index as the inputted mark
- The algorithm finishes after 30 marks have been input
Understanding the Algorithm
Purpose:To input 30 student marks and assign each mark a letter grade (A–F) based on its value.
Processes:
- Initialise a counter (Count) to 0
- Repeat 30 times: input a score and store it in the Score array
- Compare the score against grade boundaries (70, 60, 50, 40, 30)
- Store the corresponding grade in the Grade array at the same index
- Increment the counter
5. Past Paper Practice
Question 1 — Program Development Life Cycle
Four descriptions of stages in the program development life cycle are shown. Draw one line to link each description to its most appropriate program development life cycle stage. Not all stages will be used.
| Description | Stage |
|---|---|
| develop an algorithm to solve the problem by using structure diagrams, flowcharts or pseudocode | analysis / coding / design / evaluation / testing |
| detect and fix the errors in the program | analysis / coding / design / evaluation / testing |
| identify the problem and its requirements | analysis / coding / design / evaluation / testing |
| write and implement the instructions to solve the problem | analysis / coding / design / evaluation / testing |
Show Mark Scheme
Answer (4 marks):
- develop an algorithm... →design
- detect and fix the errors... →testing
- identify the problem and its requirements →analysis
- write and implement the instructions... →coding
Question 2 — Component Parts After Decomposition
Identify three of the component parts after a problem has been decomposed. [3 marks]
Show Mark Scheme
Answer (3 marks):
- inputs— what is put into the system
- processes— actions taken to achieve a result
- outputs— what is taken out of the system
- storage— what needs to be kept for future use
Question 3 — First Stage of the SDLC
Tick one box to identify the first stage of the program development life cycle. [1 mark]
Show Mark Scheme
Answer:
A Analysis— [1 mark]
Analysis comes first because you must understand the problem before you can design a solution.
Question 4 — Ways to Present a Design
Identify three different ways that the design of a solution to a problem can be presented. [3 marks]
Show Mark Scheme
Answer (3 marks):
- Structure diagram / chart
- Flowchart
- Pseudocode
Question 5 — Food Ordering System Structure Diagram
A food ordering system is an example of a computer system that is made up of sub-systems. The food ordering system:
- allows the user to enter the details of the food they want to order and to pay for the order
- displays food available as pictures or as a list
Complete the structure diagram for the given parts of the food ordering system. [4 marks]
Show Mark Scheme
Mark Scheme (max 4):
- [1 mark]A suitable hierarchical structure
- [1 mark]Suitable names for the sub-systems for user input and display options
- [1 mark]Sub-systems for user inputs (choice of display, food order and payment)
- [1 mark]Sub-systems for display output types (pictures and list)
Key Takeaways
- Analgorithmis a specific sequence of steps that can be followed to complete a task.
- Acomputer programis an implementation of an algorithm — but an algorithm is not a computer program in itself.
- Every algorithm can be built from three building blocks:sequence,selectionanditeration.
- There arethree main ways to design an algorithm: structure diagrams, flowcharts and pseudocode.
- Structure diagramsshow hierarchical top-down design — each problem is divided into sub-problems, and each sub-problem into further sub-problems.
- Flowchartsuse standard shapes: oval (terminator), parallelogram (input/output), rectangle (process) and diamond (decision).
- Pseudocodeis a text-based tool using short English statements. It is not real code — don't use language-specific syntax likeprint().
- Whenstating the purposeof an algorithm, clearly define what problem it addresses and what the expected outcome is.
- Whendescribing the processesof an algorithm, detail the individual steps, conditions and loops involved.
- To understand a complex algorithm, look forcomments, consider thecontext, andtest with different inputs.
- Following the algorithm instructions should make itspurpose clearto a new user.
Question Bank
1. Define the term "algorithm" and explain the relationship between an algorithm and a computer program. [4 marks]
Answer
- [1 mark]An algorithm is a specific sequence of steps that can be followed to complete a task
- [1 mark]It is a precise set of rules or instructions to solve a specific problem
- [1 mark]A computer program is an implementation of an algorithm
- [1 mark]An algorithm is not a computer program in itself — it can exist independently of any programming language
2. Name the three main ways to design an algorithm and briefly describe each. [6 marks]
Answer
- [2 marks]Structure diagrams— show hierarchical top-down design in a visual form; each problem is divided into sub-problems and each sub-problem into further sub-problems
- [2 marks]Flowcharts— a visual tool that uses shapes to represent different functions; shows input, output, processes, decisions and repetition using lines to show the flow of control
- [2 marks]Pseudocode— a text-based tool that uses short English words/statements to describe an algorithm; more structured than English but very flexible
3. Describe the four main shapes used in a flowchart and what each represents. [4 marks]
Answer
- [1 mark]Oval (terminator) — start or stop
- [1 mark]Parallelogram (input/output) — data entering or leaving the algorithm
- [1 mark]Rectangle (process) — a process or action
- [1 mark]Diamond (decision) — a yes/no question or condition
4. State the purpose of the following algorithm in one sentence and list its processes. [4 marks]
Count ← 1
Number ← 0
Total ← 0
REPEAT
INPUT Number
Total ← Total + Number
Count ← Count + 1
UNTIL Count > 10
OUTPUT Total
Answer
Purpose:
- [1 mark]The purpose of the algorithm is to add ten user-entered numbers together and output the total
Processes:
- [1 mark]Initialising three variables (Count, Number, Total)
- [1 mark]Inputting a user number and adding to two variables (Total, Count)
- [1 mark]Repeating nine more times, then outputting the final Total value
5. Write CIE pseudocode for a program that asks the user to enter an age. If the age is 18 or over, it outputs "Welcome to the site". Otherwise, it outputs "Sorry, this site is for users 18 and over". [5 marks]
Answer
Marking:INPUT statement (1), correct IF condition (1), correct THEN output (1), correct ELSE output (1), ENDIF (1).
6. Explain how a well-designed algorithm helps a new user understand what it does. [3 marks]
Answer
- [1 mark]A well-designed algorithm can be interpreted by a new user who should be able to explain what it does
- [1 mark]Following the algorithm instructions should make its purpose clear
- [1 mark]If the algorithm is complex, the user can look for comments, consider the context of where it is used, or test it with different inputs
7. The following algorithm is presented as pseudocode. Describe what happens in this algorithm. [3 marks]
Total ← 0
FOR i ← 1 TO 5
INPUT Mark
Total ← Total + Mark
NEXT i
Average ← Total / 5
OUTPUT Average
Answer
- [1 mark]Five marks are input and added to a running total
- [1 mark]The total is divided by 5 to calculate the average
- [1 mark]The average is output to the user
8. Explain why pseudocode is not real code and why using real code syntax can lose marks in an exam. [3 marks]
Answer
- [1 mark]Pseudocode is a simplified form of programming code that does not worry about the actual rules and syntax of a particular language
- [1 mark]Using real code syntax such asprint()orinput()with brackets shows you are not using the standard pseudocode style
- [1 mark]The exam expects simple statements likeINPUT AgeandOUTPUT "Welcome"— adding actual language syntax can lose you marks because it is not the correct pseudocode format