Algorithms PDF
Algorithms PDF
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
(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
(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
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.
Statements
+ c accumulator statement
EndFor
Repeat Unit
Repeat
Statements to be TRUE
Until (condition) repeat until
Condition becomes TRUE