defining and creating algorithms
defining and creating algorithms
Page 1 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
What is an input?
An input is data or information being entered/taken into a program before it is processed in the
algorithm
An input can come from a variety of sources, such as:
User - keyboard, mouse, controller, microphone
Sensors - temperature, pressure, movement
What is a process?
A process is a doing action performed in the algorithm that transforms inputs into the desired output.
The central processing unit (CPU) executes the instructions that define the process
An example would be:
Comparing two numbers
Calculating an average
What is an output?
An output is the result of the processing in an algorithm and usually the way a user can see if an
algorithm works as intended
An output can take various forms, such as:
Numbers - result of calculations
Text
Images
Actions - triggering events
Page 2 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Worked Example
A bus company offers a discount to passengers if they have a valid 'student' card or are over 65
years of age.
Identify all the inputs that will be required in an algorithm to solve this problem [2]
Answer
Student card (YES/NO)
Age (integer)
Page 3 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Structure Diagrams
Your notes
Structure Diagrams
What is a structure diagram?
A structure diagram is a visual representation of problem decomposition
A tool to show how a complex problem can be broken down into more manageable sub problems
A planning tool for developers during the analysis of a problem
Worked Example
A hairdressers uses a mobile phone app to allow clients to book appointments.
Clients must log in before they can use the system. They then choose to book a new appointment,
view all appointments already made or update their personal details. If clients choose to view their
appointments, they can either view them on-screen or print them off.
Page 4 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
A structure diagram has been used to design the mobile phone app.
Your notes
Write one letter from the following table in each space to complete the structure diagram [4]
Letter Task
Answer
Page 5 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 6 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Pseudocode
What is pseudocode?
Pseudocode is a text based tool that uses short English words/statements to describe an algorithm
Pseudocode is more structured than writing sentences in English, but is very flexible
Example
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 then they are given a suitable message
Pseudocode
INPUT age
ELSE
END IF
The casino would like the algorithm refined so that the user also enter their first name and this is used
to greet the user when they access the site
Page 7 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Pseudocode
Your notes
INPUT fname
INPUT age
ELSE
END IF
Examples
Function OCR exam reference language
OUTPUT print("Hello")
...
...
endif
Page 8 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
...
endwhile
Worked Example
Page 9 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 10 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
ELSE else
END IF end if
Flowcharts
What is a flowchart?
Flowcharts are a visual tool that uses shapes to represent different functions to describe an
algorithm
Flowcharts show the data that is input and output, the processes that take place and any decisions or
repetition
Lines are used to show the flow of control
Page 11 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Example
Flowchart Your notes
Page 12 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
The casino would like the algorithm refined so that the user also enter their first name and this is used
to greet the user when they access the site
Your notes
Flowchart
Page 13 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 14 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 15 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Syntax Errors
What is a syntax error?
A syntax error is an error that breaks the grammatical rules of a programming language and stops it
from running
Examples of syntax errors are:
Typos and spelling errors
Missing or extra brackets or quotes
Misplaced or missing semicolons
Invalid variable or function names
Incorrect use of operators
Incorrectly nested loops & blocks of code
Examples
Syntax Errors Corrected
num1 = imput("Enter the first number") num1 = input("Enter the first number") # Misspelt word
Page 16 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
num2 = input(Enter the second number) num2 = input("Enter the second number") # Missing quotes
if num1 > num2 then if num1 > num2 then Your notes
print(num1 + " is larger") print(num1 + " is larger") # Block not indented
elseif num2 > num1 then elseif num2 > num1 then
else else
print("The numbers are the same") print("The numbers are the same")
endif endif
Logic Errors
What is a logic error?
A logic error is where incorrect code is used that causes the program to run, but produces an
incorrect output or result
Logic errors can be difficult to identify by the person who wrote the program, so one method of finding
them is to use 'Trace Tables'
Examples of logic errors are:
Incorrect use of operators (< and >)
Logical operator confusion (AND for OR)
Looping one extra time
Indexing arrays incorrectly (arrays indexing starts from 0)
Using variables before they are assigned
Infinite loops
Example
An algorithm is written to take as input the number of miles travelled. The algorithm works out how
much this will cost, with each mile costing £0.30 in petrol. If this is greater than £10.00 then it is
reduced by 10%.
Page 17 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
miles = input("Enter the number of miles) miles = input("Enter the number of miles")
endif endif
print(cost) print(cost)
Commentary
The cost was set to 0.3 (30p) instead of correctly calculating the cost of the trip by applying the
formula, miles * 0.3
The cost should only be reduced if the cost is greater than 10, in the original algorithm it only
checked if the cost was equal to 10
To calculate a discount of 10%, either calculate what 10% is and subtract it from the original or
multiply the full cost by 0.9. In the original algorithm it calculates what 10% is and sets the cost to
equal it.
Worked Example
Nine players take part in a competition, their scores are stored in an array. The array is named scores
and the index represents the player
Array scores
Index 0 1 2 3 4 5 6 7 8
Score 7 9 2 11 8 4 13 10 5
The following program counts the total score of all the players
for x = 1 to 8
total = 0
Page 18 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
next x
for x = 0 to 8
next x
print(total)
Page 19 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Trace Tables
Your notes
Trace Tables
What is a trace table?
A trace table is used to test algorithms and programs for logic errors that appear when an algorithm or
program executes
Trace tables can be used with flowcharts, pseudocode or program code
A trace table can be used to:
Discover the purpose of an algorithm by showing output data and intermediary steps
Record the state of the algorithm at each step or iteration
Each stage of the algorithm is executed step by step.
Inputs, outputs, variables and processes can be checked for the correct value when the stage is
completed
Page 20 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 21 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
3 7 7
4 1
5 8 8
6 3
7 6
8 9 9
9 12 12
Worked Example
01 X=5
02 Y=3
03 while X > 0
04 Y=Y+6
Page 22 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
05 X=X-1
Complete the following trace table for the given algorithm, the first two lines have been filled in for
you
Answer
Page 23 of 23
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers