2.
1 Algorithm Design and
Problem Solving
All Syllabi References in 2.1.1
Definition
• An algorithm is a logical step by step approach
to solving a problem, that has the beginning
and the end.
• Algorithms’ efficiency are determined by how
fast it solves the problem, how easy it is to
implement, the easier the better, how much
computer memory it uses, the lesser the
better.
Documentation of algorithms
• Algorithns are documented using either the
flowchart, pseudocode or structured english.
• For the reason above we will double do or triple
do our solutions, that means for every
pseudocode we present as solution, we should
also be able to present its flow diagram or
program code.
• You won’t be asked to write structured english,
but you should be able to read one when you see
it and even know that it is structured english.
How to implement algorithms
• There are four basic constructs used in
implementing Algorithms, they are
Assignment
Sequence
Selection
Iteration
One, some or all of these constructs may show in an
Algorithm. This is more like saying when you do your
flowchart /pseudocode, we expect to see the use of
one of/some of/all of the constructs above.
INPUTS/PROCESS/OUTPUTS
We also expect to see algorithms consisting of
input, output and process. Not all may show in
the algorithm but atleast one should always
show.
Flowchart Symbols
Identifier tables
• Identifier table is a table used to help us determine what
variables(identifiers) will be used and for what purpose in the production
of a solution.
• Eg if you are looking for Area of circle we could have this kind of identifier
table
Identifier Data type Description
area REAL Stores calculated area
PI REAL Constant that is used to determine area
radius REAL Squared and multiplied with PI, input by
user
STRUCTURED ENGLISH VERSION
• Declare area, radius and pi
• Set PI to 3.142
• Make the radius input
• Calculate area using formula area =pi
multiplied by radius squared
• Output the area
Example of implementation of
Algorithm
• We use the same example from finding an area of circle. Using PSEUDOCODE
• START
• DECLARE area,radius: REAL
CONSTANT PI 3.142 //declaration and initialisatiion
• INPUT radius
• area PI * radius*radius
• OUTPUT area
• STOP
• ===========================================================================
If user inputs radius of 10, the value calculated for area will be 314.2
Continuation
• Same example using flowchart
START In flowcharts there are
no declarations
PI 3.142
INPUT
radius
areaPI*radius*radius
OUTPUT area
STOP