KU02 AA AlgorithmAnalysis
KU02 AA AlgorithmAnalysis
Analysis &
Importance
Algorithm
Importance
Analysis of
Engineering Algorithms
Analysis of
Algorithm
Importance
Algorithm and its
Importance
Analysis of
Algorithms
1 Algorithm Importance Analysis of
Algorithms
2 Analysis of Algorithms
Analysis of Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Review of Algorithm Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Techniques of Expressing Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
• (2) Pseudo-code,
• (3) Flow charts.
Simple Examples
• (1) Write an algorithm to determine a student’s final
grade and indicate whether it is passing or failing.
• (2) The final grade is calculated as the average of
four marks.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Importance of Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
Analysis of
Computer process a large amount of data. The program Algorithms
must terminates within a reasonable amount of time. Analysis of
Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Importance of Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
A program is an implementation of an algorithm. Analysis of
Algorithms
Analysis of
Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Importance of Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
A program is an implementation of an algorithm. Analysis of
Algorithms
Analysis of
Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Importance of Algorithms Analysis &
Importance
Algorithm
Importance
The speed of hardware computation of basic operations Algorithm and its
Analysis of
more than ever today. Algorithms
Analysis of
Algorithms
Algorithm
Importance
Algorithm and its
Importance
Analysis of
On the other hand (and more importantly), an algorithm Algorithms
may be so inefficient that, even with computation speed Analysis of
Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Analysis of Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
A field of computer science. Describe the complexity of Analysis of
algorithms. Algorithms
Analysis of
Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Analysis of Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
Analyzing an algorithm determines the amount of time Analysis of
and space that algorithm takes to execute. Two questions Algorithms
Analysis of
we always ask about algorithm: Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Analysis of Algorithms Analysis &
Importance
time of algorithm.
• How much memory space the computer needs for
data and code?
• Whether an algorithm produces correct calculations.
• How complex a program is?
• How much longer does the Algorithm take when the
size of data increase?
• How well it deals with unexpected results?
• The ability to do an analysis usually provides insight
into designing efficient algorithms.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Why Study Analysis of Algorithms? Analysis &
Importance
Algorithm
Importance
• A toolbox of standard algorithmic techniques. Algorithm and its
Importance
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Why Measure Time in Analysis of Analysis &
Importance
Algorithms?
Algorithm
Importance
Algorithm and its
Importance
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Measuring Time in Analysis of Algorithms? Analysis &
Importance
Algorithm
How to Measure Time in Analysis of Algorithms Importance
Algorithm and its
Analysis of
“time” that algorithm takes to execute. Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Experimental Approach of Algorithm Analysis Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
The best way if feasible. Analysis of
Algorithms
Reasons which reject the use of Experimental Analysis of
Algorithms
Approach
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Experimental Approach of Algorithm Analysis Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
The best way if feasible. Analysis of
Algorithms
Reasons which reject the use of Experimental Analysis of
Algorithms
Approach
• We would like to eliminate the bad ones early.
• This method does not enable you to reason about
whether the efficiency can be improved.
• 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.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Experimental Approach of Algorithm Analysis &
Importance
Analysis Cont.
Algorithm
Importance
Algorithm and its
Importance
The best way if feasible.
Analysis of
Algorithms
Reasons which reject the use of Experimental Analysis of
Algorithms
Approach Cont.
• May be one Algorithm is not better written.
• Experiments can be done only on a limited set of test
inputs.
• We will have difficulty comparing the experimental
running times of two algorithms unless the
experiments were performed in the same hardware
and software environments.
• We have to fully implement and execute an algorithm
in order to study its running time experimentally.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Analytic Approach of Algorithm Analysis Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
Analysis of
Algorithms
• An algorithm consists of a set of instructions. Analysis of
Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Analytic Approach of Algorithm Analysis Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
Analysis of
• Analytic approach uses a high-level description of the Algorithms
Analysis of
algorithm instead of an implementation. Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Ananlysis of Algorithms Analysis &
Importance
Algorithm
Importance
Size of Input
The amount of memory required for representing the
input with respect to a fixed coding scheme.
Examples
• For an array => The size can be considered as the
number of its elements...
• For a graph => The size can be considered as the
number of vertices or edges...
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Analysis of Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
• Predicting the amount of resources that the Analysis of
algorithm requires. Algorithms
Analysis of
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
Analysis of Algorithms Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
Analysis of
Algorithms
• Measure the required time (time complexity) and Analysis of
Algorithms
memory (space complexity).
• Best case: Measuring the required amount of
resources for easy instances.
• Worse case: Measuring the required amount of
resources for hard instances.
• Average case: Measuring the required amount of
resources for all instances divided by the number of
instances.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
What to Count and Consider? Analysis &
Importance
Algorithm
Importance
Algorithm and its
Deciding what to count involves two steps: Importance
Analysis of
• The first is choosing the significant operations. Algorithms
Analysis of
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
What to Count and Consider? Analysis &
Importance
Algorithm
Comparison Operators Importance
Algorithm and its
• The comparison operators are all considered Importance
Analysis of
equivalent and are counted in algorithms such as Algorithms
searching and sorting. Analysis of
Algorithms
Arithmetic operators
1 Additive; Additive operators include addition,
subtraction, increment, and decrement.
2 Multiplicative; Multiplicative operators include
multiplication, division, and modulus.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
What to Count and Consider? Analysis &
Importance
Algorithm
Importance
Algorithm and its
Importance
Analysis of
In fact, some algorithms are viewed more favorably if they Algorithms
Analysis of
reduce the number of multiplications even if that means a Algorithms
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
What to Count and Consider? Analysis &
Importance
Primitive Operations
• Assigning a value to a variable. Algorithm
Importance
• Calling a method.
Algorithm and its
Importance
Analysis of
• Performing an arithmetic operation (for example, Algorithms
Analysis of
adding two numbers). Algorithms
Algorithm
Loops Importance
Algorithm and its
Importance
If/else
1 For the fragment if (condition) S1 else S2, the
running time of an if/else statement is never more
than the running time of the test plus the larger of
the running times of S1 and S2.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
What to Count and Consider? Analysis &
Importance
Algorithm
Calculation Examples Importance
Algorithm and its
Importance
• e.g. Calculate number of steps of bellow code(s)? Analysis of
Algorithms
Analysis of
// Algorithm #1 Algorithms
1. x=0;
2. for(i=0; i<n; i++)
3. x++;
// Algorithm #2
1. x=0;
2. for(i=0; i<n; i++)
3. for(i=0; i<n; i++)
4. x++;
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Algorithm
What to Count and Consider? Analysis &
Importance
Algorithm
By analyzing several candidate algorithms for a specific Importance
problem, the most efficient one can be easily identified. Algorithm and its
Importance
Analysis of
Classifying the Functions Algorithms
Analysis of
Algorithms
There are infinitely many functions. In order to compare
them with each other, we prefer to classify them as simple
functions without loss of their properties. In fact we want
to choose one simple function for each class of functions
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
The End
Questions? Comments?