What Is An Algorithm?
What Is An Algorithm?
Output
PSEUDOCODE
Pseudocode is a generic way of describing an algorithm without use of
any specific programming language syntax. As the name suggests, it
cannot be executed on a real computer, but it models and resembles real
programming code.
Pseudocode consists of short, English phrases used to explain specific
tasks within a programs algorithm and there is no real formatting or
syntax rules.
It is an efficient and environment-independent description of the key
principles of an algorithm.
The purpose of using Pseudocode is that it is easier for humans to
understand than conventional programming language code.
It is commonly used in textbooks and scientific publications that are
documenting various algorithms.
Pseudocode cannot be compiled and executed.
PROGRAM
A program is a language specific implementation of the algorithm. A
program is Synonymous with Code.
Every computer program is simply a series of instructions in a specific
order, designed to perform a specific task. A solution for a given problem
may be in the form of an algorithm or a program. An algorithm when
expressed in some programming language is called a program.
Figure 1.
CHARACTERISTICS OF AN ALGORITHM
The main characteristics of an algorithm are given below
Correctness
Efficiency
Simplicity
Generality
Non-ambiguity
Correctness
Once an algorithm has been designed, we have to prove its correctness.
This task can be accomplished by analyzing the algorithm that yields
the required results for every genuine input in a finite amount of time.
A common technique for proving the correctness of an algorithm is to
use the mathematical induction.
Proof of correctness is quite easy for some algorithm but it can be
quite complex for the others.
Efficiency
Efficiency is used to describe properties of an algorithm relating to
how much of various types of resources it consumes.
There are two kinds of algorithm efficiency: time efficiency and space
efficiency. Time efficiency indicates how fast the algorithm runs and
the space efficiency indicates how much memory the algorithm needs.
Simplicity
The simpler algorithms are easier to understand and easier to
implement.
The simplicity of an algorithm leads to a (very) flexible, efficient,
readable, small program. For few cases simpler algorithms are more
efficient than complex one but it is not always true.
For example: The Euclids algorithm is simpler than the middle
school procedure for calculating gcd (m, n)
Generality
The algorithm must be general to solve the problem. For example if
any algorithm is used to calculate the sum of first ten natural number
than it should be possible to calculate the sum of n natural numbers
when generalized.
Generality specified that algorithm should work for all valid sets of
input. It should be possible that the algorithm accept the range of
inputs that is natural for the problem.
There are some situations where the designing a general algorithm is
unnecessary or difficult or even impossible. For example: the standard
6
10
For Example,
Then the running time T (n) of the algorithm can be calculate by the
formula.
ASYMPTOTIC NOTATION
11
For a given algorithm asymptotic notation will provides upper and /or lower
time and space bounds. Upper bound gives the maximum time / space
required and lower bound gives the minimum time / space required.
A tool for analyzing time and space usage of algorithms
Assumes input size is a variable, say n, and gives time and space
bounds as a function of n
Provides simple characterization of an algorithm efficiency
Ignores multiplicative and additive constants.
Compare the growth rates of two expressions of running time.
Concerned only with the rate of growth.
12
13