Professional Documents
Culture Documents
Cs 1
Cs 1
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.
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:-