Professional Documents
Culture Documents
Algorithm Analysis
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Outline
What is an Algorithm? Algorithm Formulation Algorithm Analysis Frequency Count Operation Count
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
What is an Algorithm?
An organized sequence or list of clear steps or operations needed to solve a given programming problem 3 components:
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
What is an Algorithm?
Any well-defined computational procedure that takes some value(s) as input and produces some value(s) as output Sequence of computational steps that transform the input to output
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
What is an Algorithm?
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Can a particular task be accomplished by a computing device? What is the minimum number of steps or operations for any algorithm to perform a certain function? Concerns: effectiveness, efficiency
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Algorithm Formulation
1.
2.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Algorithm Formulation
3.
4. 5.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Algorithm Analysis
Study the behavior of the algorithm to determine its pattern and performance
Measured in terms of execution time (speed) and amount of memory (space) consumed Designing efficient algorithms
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
1.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
It is impossible to know the exact amount of time to execute any command unless the following are known:
The machine for execution machine instruction set time required by each machine instruction translation of the compiler from source to machine language
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Posteriori estimates
Study of exact time & space required for execution
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Frequency Count
a 10 ba*2
Count: 1 Count: 1
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Frequency Count
Conditional Statements
if (<condition>) <S1>; else <S2>; Sum of the following: 1 + Max{ Count(<S1>), Count(<S2>) }
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
}
Total = 3
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Frequency Count
Loop Statements
for i <lb> to <ub> <S1> ub - lb + 2 ub - lb + 1
n - 1 + 2 = n+1 n
Total = 2n+1
2x+1
Total = 2x+3
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
}
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Frequency Count
Nested Statements
for i 1 to n n+1 { xx+1 n for j 3 to n+1 n(n) { y y + 1 (n-1) (n) <S2> z z + 1 (n-1) (n) = (n-1) } }
Total = n+1 + n + n2 + (n-1)n + (n-1)n = 2n+1 + n2 + n2-n + n2-n College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines = 3n2 + 1
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Frequency Count
Loop Statements
do <S1> while <condition>
Ex.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
Frequency Count
Loop Statements
Ex.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
2.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
2.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
4.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
6.
7.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines
9.
14. 15.
College of Computer Studies, De La Salle University Manila 2401 Taft Avenue, Metro Manila 1004 Philippines