Analysis of Algorithms

You might also like

You are on page 1of 10

Analysis of Algorithms

Efficiency of Algorithms

The need for problem solving calls for algorithm


design with appropriate data structures.
The need of the hour is an efficient Algorithm.
The performance of Algorithms can be measured on
the scales of time and space.
The algorithm that performs its task in the minimum
possible time, is measured as time complexity.
The time complexity of an algorithm or a
program , is a funciton of the running time of the
algorithm.
An algorithm that consumes limited memory space
to complete its task is termed as space
complexity.

Time Complexity
The

time complexity of an algorithm


can be computed either by an
empirical or theoritical approach.

The Empirical or Posteriori


Testing
The

Empirical or Posteriori testing


calls for implementing the complete
algorithms and executing them on a
computer for various instances of
the problem. The Time taken by the
various instances of the problem are
noted and compared, to find the
algorithm with the least time taken
to finish the task.
Disadvantage Machine dependent

The Theoretical or
Apriori
The

theoretical or Apriori approach


calls for mathematically determining
the resources such as time and
space needed by the algorithm as a
function of a parameter related to
the instances of the problem.
Advantage Machine Independent

Apriori Analysis
Let

us consider a program statement


, x = x + 2 in a sequential program
environment.
Apriori Testing uses the following
measures to compute the efficiency :
The Number of times the statement is

executed in the program called as the


frequency count.
Time taken for a single execution of a
statement. ( Machine dependent)

Contd..
Thus

the Apriori Algorithm computes


the efficiency of a program as a
function of the total frequency
count.
The frequency count fi of each
statement i is computed and
summed up as the total frequency
count as T = fi

Example
Let

us consider the frequency count


of the statement x = x + 2 in the
following segments
A

x=x+2
.

B
For k = 1 to n
to
x=x+2
end

C
For j= 1 to n do
for k = 1 to
n do
x=x+2
end
End

Contd..
Total

Frequency count of Segment A

Program Statement

Frequency Count

x= x + 2

Total Frequency
Count

Total

Frequency Count of Segment B

Program Statement

Frequency Count

For k = 1 to n to
x=x+2
end

(n+1)
n
n

Total Frequency
Count

3n+1

Total

Frequency count of Segment C

Program Statement

Frequency Count

For j= 1 to n do
for k = 1 to n do
x=x+2
end
End

(n+1)
n(n+1)
n2
n2
N

Total Frequency
Count

3n2 + 3n + 1

To

be continued..

You might also like