2. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
2
Learning Outcome
ļ® By the end of this presentation, students will
be able to:
ļ± Analyze Algorithm
ļ± Identify the resources for analysis
ļ± Understand experimental approach for
analysis
ļ± Understand the analytical approach for
analysis
3. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
3
Algorithm Analysis
ļ® After correction of an Algorithm the next
step is to determine the amount of resources
(complexity of algorithms).
ļ® This step is called algorithm analysis.
ļ® Two questions we always ask about
algorithm:
ļ± Does it work correctly?
ļ± How long does it take?
ļ® The second question is not so obvious.
4. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
4
ļ® The efficiency of an algorithm:
ļ± F (steps (time complexity), storage (space
complexity), Bandwidth (I/O complexity)).
ļ® Run-time analysis:
ļ± Theoretical classification that estimates
the increase in running time of an
algorithm as its input size increases.
5. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
5
ļ® Run-time efficiency is a topic of great
interest in computer science.
ļ® A program can take seconds, hours or even
years to finish executing, depending on
which algorithm it implements.
7. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
7
Algorithm Analysis
ļ® How can we say that one algorithm performs
better than another?
ļ® Quantify the resources required to execute:
ļ± Time
ļ± Memory
ļ± I/O / Bandwidth
8. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
8
ļ® Algorithm analysis is used to:
ļ± Estimate the running time, space, I/O.
ļ± Reduce the running time.
ļ± Framework to describe the running time.
ļ± Correction of Algorithm.
ļ± The relation of time of Algorithm with the
size of data.
9. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
9
ļ± Provides insight into designing efficient
Algorithms.
ļ± Determine the bottlenecks.
ļ± Develop efficient algorithm for a given
problem.
ļ± Make better use of hardware.
10. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
10
Model of Implementation
ļ® For the analysis, we assume:
ļ± A generic one-processor
ļ± RAM model f computation
ļ± Algorithms will be implemented as
computer programs.
ļ® In the RAM model, instructions are executed
one after another (no concurrent operations)
11. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
11
Running Time Calculation
ļ® The efficiency of an algorithm is estimated
by its performance.
ļ® The performance of an algorithm can be
measured by the time, space & bandwidth
requirement.
ļ® The time, space & bandwidth requirement of
an algorithm is called the computational
complexity of the algorithm.
12. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
12
ļ® The greater the amount of the time and space
required, the more complex is the algorithm.
ļ® Which measure is more important?
ļ® Normally we are concerned with the time rather
than space.
ļ® The reasons are that:
ļ± Firstly it becomes easier and cheaper to obtain
space.
ļ± Secondly techniques to achieve space efficiency
by spending more time are available.
13. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
13
Analysis Tools
ļ® Running time is a natural measure of
goodness, since time is a precious resource.
ļ® Computer solutions should run as fast as
possible.
ļ® The running time is affected by:
ļ± Hardware environment
ļ± Software environment
14. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
14
Measuring Running Time
ļ® Factors that affect running time:
ļ± Machine
ļ± Compiler
ļ± Algorithm
ļ± Input data
ļ± CPU used by other processes (Garbage
collection)
ļ® Therefore it is difficult to get precise
measurements.
15. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
15
ļ® The amount of time depends on the amount
of input.
ļ± T = f(input size)
ļ® The exact value of the function depends on:
ļ± Speed of the host machine,
ļ± The quality of the compiler,
ļ± The quality of programs.
16. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
16
ļ® Analyzing an algorithm, time is not really a
number of seconds but the number of
operations.
ļ® The number of operations is related to the
execution time, so we will use the word time
to describe an algorithmās computational
complexity.
17. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
17
The Experimental Approach
ļ® The best way.
ļ® But, there are some reasons which reject the
use of this method:
ļ± We would like to eliminate the bad ones
early.
ļ± This method does not enable you to reason
about whether the efficiency can be
improved.
18. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
18
ļ± This method does not give you any insight
into how the program will perform if run
on different hardware or under different
conditions.
ļ± The effort involve program and testing.
ļ± May be one Algorithm is not better
written.
19. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
19
The Analytic Approach
ļ® In theoretical approach the time complexity is the
number of steps.
ļ® It characterizes running time as a function of the
input size.
ļ® It takes into account all possible inputs.
ļ® It allows us to evaluate the speed of an algorithm
independent of the hardware/software
environment.
20. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
20
ļ® Using this method we can develop a general
way of analyzing the running times of
algorithms that:
ļ® āIndependentā of actual implementation
21. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
21
Summary
ļ® In this presentation, we discussed:
ļ± Algorithm Analysis
ļ± Resources for analysis
ļ± Experimental & analytical approach for
analysis
22. Algorithm Analysis
Algorithm
Analysis
&
Design April 2020
22
Exercises
ļ® Explain by example the analysis of Algorithm
ļ® What Resources are analyzed, which resource
is more important & why?
ļ® Explain the difference between Experimental
& analytical approach.