You are on page 1of 5

An Algorithm sequence of steps that can be carried out to perform Algorithms can be expressed in the following

a task. ways:-
Consider the following as an example:- - Structured English
1 Take a spanner and loosen the wheel nuts. - Subset of English language that consists of
2 Position a jack in an appropriate place. commands to describe an algorithm.
3 Raise the car. - Pseudocode
4 Take off the wheel nuts and the wheel. - Makes use of keywords and identifiers
5 Lift replacement w heel into position . without following any particular syntax of
6 Replace wheel nuts and tighten by hand. a programming language.
7 Lower the car. - Flowchart
8 Fully tighten wheel nuts. - Makes of shapes that are linked together
These directions may seem pretty straightforward but not followed to represent the sequence in an algorithm.
correctly in sequence may result in the process becoming very
difficult maybe even impossible.
In computer Science all Algorithms make use of the following basic constructs when writing algorithms:-
- Assignment
- A value is given a name (identifier) or the value is changed.
- Sequence
- The steps the are performed on after the other.
- Selection
- Some steps are performed only under certain conditions. Otherwise different (or no steps are performed).
- Repetition
- Some steps are performed a number of times. A.K.A iteration or looping.
- Input, Processing and Output
- Programs involve data and that is why we need input and output statements.
Stages in Producing an Algorithm:-
• Make sure the problem is clearly defined.
• Break the problem into sub problems (each sub problem will require a separate algorithm)
• Problems can be divided into
• Set up
• input
• processing
• output results.
• Decide on how the data is to be stored, manipulated and then displayed.
• Decide on a method for constructing an algorithm, i.e. pseudo code or flowchart.
• Decided on suitable names (identifiers) for variable names.
• Create test data (normal, abnormal and boundary) and trace tables for finding errors.
• If any errors have been highlight then correct them and re-test the code until it works perfectly.

Is your solution effective?


To check if your solution works perfectly, you should ask yourself the following questions:-
• Does the solution work for all data sets?
• Does the solution have any unnecessary processes that are never used?
• Are there any actions or processes that run more than necessary?
• Can you can come up with a simpler solution and yet achieve the same result?
Variables:-
- It is the space allocated in the main memory to hold some data.
- And of course, it’s contents are suppose to change during execution.
- Unlike constants.
- The size of variable (bytes) depends on its type.
- A variable is referred to by its name (identifier).
Operation Pseudocode Description
Assigning a Value INPUT number Number is assigned with 5 (assuming that is what the user put in)
Guesses ß 1 The value of 1 is assigned to (ß) to Guesses
Value Guesses ß Guesses + 1 Guesses will be added to 1 and then stored in Guesses overwriting the old value
Updating/totalling with the new one.
Copying a Value Total ß Sum The contents of Sum will be copied to Total.
Swapping Two Values We will need a temporary The value of A is temporarily stored Temp. (say A was 5 now 5 is Temp)
variable…say Temp The value of B (say 6) is now copied to A (overwriting 5).
Temp ß A The Value from Temp is then copied to B (5 overwrites 6).
AßB Therefore the value of A(was 5 now is 6) and B(was 6 now is 5) are swapped.
BßTemp

Local Variables:-
Variables that are used within a single module or subroutine (to be discussed later).
Global Variable:-
Variables that are used by all modules or subroutines.
Correlating Flowcharts and Pseudocodes:-

You might also like