Design & Analysis of Algorithm (CSC-321) : Lecture 2,3 Computer Sciences Department Bahria University (Karachi Campus)
Design & Analysis of Algorithm (CSC-321) : Lecture 2,3 Computer Sciences Department Bahria University (Karachi Campus)
Lecture 2,3
Computer Sciences Department
Bahria University (Karachi Campus)
Basic MATHEMATIC FOR ANALYSIS OF
ALGORITHM
Learning Outcomes
In this Lecture will learn ......
To review basic mathematics of Summation
To solve a harder example
Summations
• Used summation to analyze the time
complexity of a loop
For i: 1 to 10
Print i
end
Properties of summation
Arithmetic series
For n >= 0
Geometric series
Harmonic series
• For n >= 0
Quadratic series
Example
Let I(j) is the time to execute inner most loop
// Here c is a constant
for (int i = 1; i <= c; i++)
{
// some O(1) expressions
}
• 2) O(n): Time Complexity of a loop is
considered as O(n) if the loop variables is
incremented / decremented by a constant
amount. For example following functions have
O(n) time complexity