0% found this document useful (0 votes)
11 views

Algorithms

Uploaded by

MrFeast
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Algorithms

Uploaded by

MrFeast
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Head to www.savemyexams.

com for more awesome resources

Cambridge (CIE) O Level Your notes


Computer Science
Algorithms
Contents
Designing Algorithms
Explaining Algorithms

Page 1 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Designing Algorithms
Your notes
What is an algorithm?
An algorithm is precise set of rules or instructions to solve a specific problem or task
There are three main ways to design an algorithm
Structure diagrams
Flowchart
Pseudocode

Structure Diagrams
What is a structure diagram?
Structure diagrams show hierarchical top-down design in a visual form
Each problem is divided into sub-problems and each sub-problem divided into further sub-problems
At each level the problem is broken down into more detailed tasks that can be implemented using a
single subroutine

an example of a structure diagram for a mobile application could be:


Page 2 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Your notes

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 3 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Your notes

Example
Flowchart

Page 4 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Your notes

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

Page 5 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Flowchart
Your notes

Page 6 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Your notes

Page 7 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Pseudocode Your notes

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

IF Age >= 18

THEN

OUTPUT "Welcome to the site"

ELSE

OUTPUT "Sorry, this site is for users 18 and over"

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

Pseudocode

INPUT FName

INPUT Age

IF Age >= 18

THEN

OUTPUT "Welcome to the site", FName

ELSE

OUTPUT "Sorry, this site is for users 18 and over"

Page 8 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Explaining Algorithms
Your notes
Explaining Algorithms
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 then additional ways to understand the problem could be:
Look for comments in the code
Consider the context of where the algorithm is being used
Test the algorithm with different inputs
Look at the following algorithm, can you explain what it does?

Pseudocode

Count ← 1

Number ← 0

Total ← 0

REPEAT

INPUT Number

Total ← Total + Number

Count ← Count + 1

UNTIL Count > 10

OUTPUT Total

The purpose of the algorithm is to add ten user-entered numbers together and output the total

Page 9 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

The processes are:


initializing three variables (Count, Number, Total) Your notes
inputting a user number
adding to two variables (Total, Count)
repeating nine more times
outputting the final Total value

Worked Example
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.
Count ← 0

REPEAT

INPUT Score[Count]

IF Score[Count] >= 70

THEN

Grade[Count] ← "A"

ELSE

IF Score[Count] >= 60

THEN

Grade[Count] ← "B"

ELSE

IF Score[Count] >= 50

THEN

Grade[Count] ← "C"

ELSE

IF Score[Count] >= 40

THEN

Page 10 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources

Grade[Count] ← "D"

ELSE Your notes


IF Score[Count] >= 30

THEN

Grade[Count] ← "E"

ELSE

Grade[Count] ← "F"

ENDIF

ENDIF

ENDIF

ENDIF

ENDIF

Count ← Count + 1

UNTIL Count = 30

Describe what happens in this algorithm.


[3]
Answer
Any 3 of:
Inputted marks are stored in the array Score[] [1]
Marks are then checked against a range of boundaries [1]
A matching grade is assigned to each mark that has been input [1]
The grade is then stored in the array Grade[] [1]
At the same index as the inputted mark [1]
The algorithm finishes after 30 marks have been input [1]

Page 11 of 11
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers

You might also like