Algorithm
Algorithm
Characteristics of an Algorithm
Not all procedures can be called an algorithm. An algorithm should have the
following characteristics −
Example
Problem − Design an algorithm to add two numbers and display the result.
Step 1 − START
Step 6 − print c
Step 7 – STOP
Algorithms tell the programmers how to code the program. Alternatively, the
algorithm can be written as −
Step 3 − c ← a + b
Step 4 − display c
Step 5 − STOP
• Start
• Read 3 numbers a,b,c
• Compute sum = a+b+c
• Compute average = sum/3
• Print average value
• Stop
Algorithm Analysis
Efficiency of an algorithm can be analyzed at two different stages, before
implementation and after implementation. They are the following −
We shall learn about a priori algorithm analysis. Algorithm analysis deals with the
execution or running time of various operations involved. The running time of an
operation can be defined as the number of computer instructions executed per
operation.
Algorithm Complexity
Suppose X is an algorithm and n is the size of input data, the time and space used
by the algorithm X are the two main factors, which decide the efficiency of X.
The complexity of an algorithm f(n) gives the running time and/or the storage
space required by the algorithm in terms of n as the size of input data.
Space Complexity
Space complexity of an algorithm represents the amount of memory space required
by the algorithm in its life cycle. The space required by an algorithm is equal to the
sum of the following two components −
• A fixed part that is a space required to store certain data and variables, that
are independent of the size of the problem. For example, simple variables
and constants used, program size, etc.
• A variable part is a space required by variables, whose size depends on the
size of the problem. For example, dynamic memory allocation, recursion
stack space, etc.
Algorithm Program
An algorithm provides abstract steps for The constituents of a program may not be
processing one sequence of related conceptually related.
information into a different sequence of
derived information.