ConceptX International School
ALGORITHM
Pseudo code and Flow Chart
Prepared by Daw May Thu Aung
M.E(Electronics), Ph.D(Course Work)
Algorithm is a set of rules to be followed by a person or a
computer to solve a specific problem. Every algorithm must satisfy
the following criteria:
Input
Output
Definiteness
Finiteness
Effectiveness
WRITTEN DESCRIPTIONS
A written description is the simplest way of expressing an
algorithm. Here is an algorithm describing the everyday task of
making a cup of instant coffee.
ALGORITHM FOR MAKING A CUP OF COFFEE
❖ Fill kettle with water.
❖ Turn on kettle.
❖ Place coffee in cup.
❖ Wait for water to boil.
❖ Pour water into cup.
❖ Add milk and sugar.
❖ Stir.
Algorithms
Discuss many cases about problem solving using
algorithms
How to prepare for your exam
How to find the area of triangle, square, rectangle, circle
How to calculate the velocity of a car
How to know your crush’s address
How to cook a fried chicken curry
How to make a mango juice
ACTIVITY 1
GETTING TO SCHOOL
Produce a written description of an algorithm for getting to
school.
It should start with leaving home and end with arriving at
school. For example, the algorithm could start with 'Walk to
bus stop’.
Check your algorithm with other members of the group.
Would your algorithm work for others? Are there any general
statements that are common to all algorithms?
2 CREATING ALGORITHMS
LEARNING OBJECTIVES
Understand how to create an algorithm to solve a particular
problem
Make use of programming constructs (sequence, selection and
iteration) and use appropriate conventions (flowchart,
pseudocode, written description, draft program code)
Problem Solving and the Computer
In order to understand how a computer system is built up and how
it works it is often divided up into sub-systems. This division can be
shown using top-down design to produce structure diagrams that
demonstrate the modular construction of the system. Each sub-system
can be developed by a programmer as a sub-routine.
How each sub-routine works can be shown by using flowcharts or
pseudocode.
Flowchart shows an algorithm as a diagram. Each step in the
algorithm is represented by a symbol. Symbols are linked together
with arrows showing the order in which steps are completed
Symbols of Flowchart
Terminators
Begin End Indicates the start or end of an algorithm
Process
COUNT=COUNT+1 Indicates a process to be carried out
Subprocess
Subprocess A procedure that is already
documented somewhere else
Input and Output
Read a card Write square root Indicates an input or output
Decision
False True
Max > Min Indicates a decision to be made
Connector Represents the Continuity of
the flowchart in another place /
page
Flow of Algorithm
Shows the logical flow of the algorithm
Flowchart of an
algorithm to
The flowchart of an
algorithm for
making a cup of
coffee as a written
description
mentioned above.
Operators
(1) Arithmetic Operators
+,-,*,/ (eg. + means “addition”)
(2) Relation Operators
= , > , < , >= , <= (eg. = means “equal to”)
(3) Logical Operators
They are used for conditions to be linked and, or, not
&& , || , ^ (eg. && means “AND operation”)
Operator precedence
Eg. ( ) ,index or power, / , * , + , -
Variables
The value stored by a variable can change as a program
is running. Variables are extremely useful in programming
because they make it possible for the same program to
process different sets of data.
Constant
A 'container' that holds a value that never changes; like
variables, constants have unique identifiers. Constants are
useful for storing fixed information, such as the value of pi,
the number of liters in a gallon or the number of months in
a year.
Pseudo-code in use
In addition to flowcharts and written descriptions, algorithms can
also be expressed in pseudocode, a structured, code-like language that
can be used to describe an algorithm. The pseudocode can be used to
code the solution in an actual programming language.
Pseudo-code is a common language for computer programming
languages.
ACTIVITY 4
INVESTIGATING PSEUDOCODE
Different organizations or examination boards have their own unique
versions of pseudocode. Investigate the Pearson Edexcel
pseudocode that you will need for your International GCSE course
and which will be used in this book.
WRITTEN DESCRIPTION
ALGORITHM FOR ADDING TWO NUMBERS
➢ Enter first number.
➢ Enter second number.
➢ Calculate total by adding first and second numbers.
➢ Output total.
PSEUDOCODE
ALGORITHM FOR ADDING TWO NUMBERS
➢ SEND 'Please enter the first number' TO DISPLAY
RECEIVE frstNumber FROM KEYBOARD
➢ SEND 'Please enter the second number' TO DISPLAY
RECEIVE secondNurnber FROM KEYBOARD
➢ SET total TO firstNurnber + secondNurnber
➢ SEND total TO DISPLAY
ACTIVITY 2
SCHOOL JOURNEY FLOWCHART
Display the 'journey to school' algorithm that you created in Activity 1
as a flowchart.
ACTIVITY 3
BATH FLOWCHART
A student has created a written algorithm for preparing a bath.
Working with a partner, display the following as a flowchart. You
may need to change the order or add actions.
❑ Put in the plug.
❑ Fill the bath to the correct level.
❑ Check the temperature is OK.
Start
Enter first
Example (1) Write a algorithm number
description and flowchart to find
Enter second
number
the different of two numbers
difference=first number-
Written Description second number
❖Write down first number
❖Write down second number Output difference
❖Subtract the two numbers
❖Output the answer End
Flowchart for sum of two numbers
PSEUDOCODE
ALGORITHM FOR ADDING TWO NUMBERS
➢ SEND 'Please enter the first number' TO DISPLAY
RECEIVE frstNumber FROM KEYBOARD
➢ SEND 'Please enter the second number' TO DISPLAY
RECEIVE secondNurnber FROM KEYBOARD
➢ SET total TO firstNurnber + secondNurnber
➢ SEND total TO DISPLAY
Control Structures
Algorithm and their equivalent computer programs are
more easily understood if they mainly use self-contained
modules. There are three types of logic, or flow of control
called
Sequence logic, or sequential flow
Selection logic, or conditional flow
Iteration logic, or repetitive flow
Construct a smaller part from which something is built.
Letters and numbers (i.e. a to z and Oto 9) are the
constructs we use to build our language and convey
meaning. Bricks and cement are the basic constructs of a
building
Selection a construct that allows a choice to be made
between different alternatives
Iteration a construct that means a process is repeated. An
action is repeated until a condition is met or a particular
outcome is reached. It is often referred to as a 'loop'
Sequence Logic
The sequence may be presented explicitly, by means of numbered
steps.
Most processing, even of complex problems will generally follow this
elementary flow pattern. Instructions will then be performed
sequentially.
Selection Logic
The selection logic employs a number of conditions, which lead to a
selection of one out of several alternative statements.
When we need to do one sequence if a condition is true and nothing some
second sequence, if the condition is false.
True
condition
False
Module A
Selection Structure
Example (1) Checking the number is
positive or not.
Single Alternative
Written Description
If < condition > then
[Module A] ❖Write a number
end if; ❖If it is greater than zero, it is positive
number
❖If it is less than zero, doesn’t show any.
Double Alternative Example (2) Checking the number is even or
If < condition > then odd number.
[Module A] Written Description
else ❖ Enter a number
[Module B] ❖ If it is evenly divided by 2, it is even number
end if ; ❖ If not, it is odd number
Example(3) Write a written description and flowchart
which read a mark from the keyboard and determine as
follow.
Nested Selection mark < 40 (fail)
If < condition 1 > then 40<= mark < 80 (pass)
mark>= 80 (pass with credit)
[Module A]
else if < condition 2 > then
Written Description
[Module B]
❖ Check the mark
else ❖ Mark is less than 40, show the result as “fail”
[Module C] ❖ Mark is greater than or equal to 80, show the result as
end if ; “pass with credit”
❖ The other conditions, show the result as “pass"
ITERATION
When writing programs, it is often necessary to repeat
the same set of statements several times.
Instead of making multiple copies of the statements,
you can use iteration to repeat them.
Iteration Logic
This logic refers involving loops.
Each type begins with a repeat called the body of the loop.
Body of loop
condition
True
False
Iteration Structure
Loop condition
Example(3) Susan works at a bakery as
while< condition > do a baker. When the customer orders the
[Module A] cake or bread, she has to bake
end while
immediately to be hygienic and to
for< condition > To
[Module B] reduce waste.. Write a pseudo-code and
Next flowchart for Susan’s working
condition.