Вы находитесь на странице: 1из 3

Objective Five

Explain the Concept Of Algorithm

An Algorithm is a finite number of accurate, unambigious steps that solve a problem or task. It may also be
defined as a sequence of instructions which rigorously defines a solution to a problem.

A Program is a set of instructions written in a programming language that directs the computer to solve a
problem.

Characteristics of an Algorithm

A good algorithm should have the following characteristics:

A finite number of steps


The steps must be precise
The steps must be unambigious
The steps must have a flow of control from one step to another
The steps must terminate thus leading to an output

Steps For Developing Algorithms

(1) The Input step this is where the instruction from the user are gathered.
(2) The Processing step this is where the instructions are worked through. It may involve all or some of the
following steps.
Assignment values are assigned to variables.
Decisoin this step is included when you have to check for any conditions to be followed.
Repetition when you have to repeat a task a specified number of times, then this step is
included.
(3) The Output step - this step is used to display the results.

Objective Six

Indentifying Ways Of Representing Algorithm

Algorithms can be represented in THREE different ways: -

(1) Narrative also called General Algorithm, is where each step is written in clear, simple, language. It does
not use any comp. lang. or code.
(2) Pseudocode a language consisting of English like statements to define algorithms. Even though the
terms used closely resemble programming language terms, they are used without following ridig rules.
(3) Flowcharts a diagrammatic representation of an algorithm

Pseudocodes

Pseudocodes can contain variables, constants, operators and terminologies used in programming languages.

Operators - these are symbols used for performing calculations or making comparisons. Commonly used
operators in pseudocodes are:
Arithmetic Relational Logical
+ Addition > greater than AND and
Substraction < less than OR or
NOT not
Multiplicaion >= greater than or equal to
/ Division <= less than or equal to
<> not equal to
= equal to

Truth Tables

AND OR NOT

Input Output Input Output Input Output


A B A B A
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1

Control Structures

Control structures are instructions or statements that determine the flow of control of steps in an algorithm.

They are:

(1) Sequence instructions are written in the order they should take place.
(2) Selection/ Conditional a choice has to be made between two or more options.
(3) Interaction/ Repetition/ Looping are used to repeat a certain process a number of times.
Repetition of a set of instructions a fixed number of times is called bounded or definite iteration.
Repeating a set of steps a number of times until a particular condition becomes false is called
unbounded iteration or indefinite iteration.

Selection Structure Format


If Then - EndIf
If (condition) Then
Statements
EndIf
If Then Else EndIf
If (condition) The
Statements (true)
Else
Statements (false)
EndIf
NB//: The If statement is a conditional statements, that is, it causes execution of some statement to
depend on the truth value of a certain statements, given as a Boolean expression. If the condition is
TRUE, the statements immediately after THEN are executed; if the is FALSE, the statement after ELSE
is executed.
Bounded/Definite Repetition Format
For Do EndFor

Set counter variable e.g. = = 0

For (counter variable start value to final value) Do

Statements

+ c accumulator statement

EndFor

Unbounded/Indefinite Loop Format


While Do - End While
While (condition) Do
statements
EndWhile

Repeat Unit

Repeat
Statements to be TRUE
Until (condition) repeat until
Condition becomes TRUE

Вам также может понравиться