
85
4.1 Algorithms
4 Algorithms and flowcharts
4.1 Algorithms
Before we look at how to write or edit an algorithm, let us consider what is
meant by an algorithm. In computer science, information technology and
mathematics, an algorithm is a set of instructions sequenced to solve a problem
or to represent a calculation. Some would say that an algorithm is basically a data
or
program flowchart without the boxes. It is actually a list of precise steps.
The order in which these steps are carried out is always crucial to the way an
algorithm works. We start at the first line of the algorithm and work downwards
to the final instruction. When an algorithm is created to produce information,
data is input, processed, then the result is output. An algorithm must be carefully
designed. It must be written in a way that caters for all possible scenarios. Any
steps that rely on decisions being made must be dealt with in sequence and
the conditions must be clear and unambiguous. Depending on the way the
algorithm is written, not all instructions are carried out for a particular scenario,
but they still have to be written in a way that allows for all possible scenarios.
Algorithms can be written in many different ways, including everyday natural
language,
pseudocode, flowcharts or programming languages. Natural
language can sometimes lead to instructions which are open to interpretation
and so tends not to be used in very complex algorithms. Pseudocode and
flowcharts are structured ways of writing algorithms and we will concentrate on
these approaches. Programming languages are primarily intended for converting
algorithms to a form that can be understood and executed by a computer.
When solving problems in this chapter, the algorithms will be written in
pseudocode. Pseudocode is independent of any programming language. Once
the pseudocode is written and checked to make sure that it solves the problem,
In this chapter you will learn how to:
+ write a basic algorithm that demonstrates a
decision-making process
+ use conditional branching within an
algorithm
+ use loops within an algorithm
+ use nested loops within an algorithm
+ include procedures/subroutines within an
algorithm
+ edit a given algorithm
+ writeanalgorithmtosolveagivenproblem
+ editagivenflowchart
+ drawabasicprogramflowchartthat
demonstrates a decision-making process
+ drawaprogramflowcharttosolveagiven
problem
+ identify errors in an algorithm or program
flowchart for a given scenario.
Before starting this chapter you should understand the:
+ comparison operators >, <,=
+ arithmeticoperators+,-,*,/
+ orderofarithmeticaloperationsinanequation.