Algorithm analysis
Chapter one
Introduction
1
Outline
• Introduction
• Study of algorithms
• Motivation
• Efficient programs
• Objective
2
Introduction
• The same problem can frequently be solved with
algorithms that differ in efficiency.
• The difference between the algorithms may be
immaterial for processing a small number of data items,
• but these differences grow proportionally with the
amount of data.
Study of algorithms
– Design of algorithms
– Algorithm validation
– Analysis of algorithms
– Algorithm testing
3
Design of algorithms
• Various designing techniques are available which yield
good and useful algorithm.
• In the forthcoming sections, we will deal with the major
methods of algorithm design.
• These techniques are not only applicable to only
computer science but also to other areas such as
electrical engineering.
• Divide-and-conquer, dynamic programming are such
techniques.
• By studying all the techniques you can formulate good
algorithm.
4
Algorithm validation
• Algorithm validation checks the algorithm result for all
legal set of inputs.
• After designing the algorithm, it is necessary to check
the algorithm, whether it computes the correct and
desired result or not, for all possible legal set of input.
• In this phase the algorithm is not converted into the
program (of any language).
• But after showing the validity of the method, a program
can be written.
• This phase is known as program proving or program
verification.
5
Algorithm analysis
• A situation may occur where many algorithms are
available for solving a particular problem.
• It should be noted that data structure can be represented
in many ways,
• and there exists number of algorithms to implement an
operation on the said data structure.
• Such cases require the comparison of two algorithms to
implement an operation on the said data structure and
later on the better one is chosen.
6
Algorithm analysis cont’d...
• To compare the efficiency of algorithms, a measure
of the degree of difficulty of an algorithm called
computational complexity is used.
Computational complexity theory- the study of the
cost of solving problems.
• Computational complexity theory indicates:-
– How much effort is needed to apply an algorithm
or
– How costly it is.
7
Algorithm analysis cont’d...
The analysis of algorithm focuses on:-
– Time complexity
– Space complexity
• The amount of memory needed by program to run to
completion is referred to as space complexity.
• The amount of time needed by an algorithm (program) to
run to completion is referred to as time complexity.
8
Algorithm analysis cont’d...
• For an algorithm, time complexity depends upon the
size of the input, thus, it is a function of input size
“n”.
• It should be noted that different time can arise for the
same algorithm.
• Usually we deal with the best case time, average
case time, and worst case time for an algorithm.
9
Algorithm testing
This phase involves testing of a program.
It consists of two phases:-
• Debugging- involves the process of finding and
correcting an errors.
• Performance measurement- describes the correct
program execution for all possible data sets.
10
Motivation:
Why we study this subject?
– Efficient algorithm leads to efficient programs.
– Efficient program sell better.
– Efficient program make better use of hardware.
– Programmers who write efficient programs are more
marketable than those who don’t.
11
Efficient programs
Factors influencing program efficiency:
– Problem being solved
– Programming language
– Compiler
– Programmer ability
– Programmer effectiveness
– Algorithm
12
Objective
What will you get from this course?
– Methods for analysing algorithm efficiency
– A toolbox of standard algorithm design techniques
– A toolbox of standard algorithms.
13