You are on page 1of 10

Lecture# 20

Analysis of Algorithms

By
Engr. Mohammad nawaz
nawazmeer@buetk.edu.pk
Lecturer at CSE&S Department
Balochistan UET khuzdar
Analysis of Algorithms
• Analysis of an algorithm is the process of calculating Time and Space
required by that algorithm.
• The Time requirement of an algorithm(not program) to complete its
Execution is the time complexity of the algorithm
• The Total amount of computer memory required by an algorithm to
complete its execution is called as space complexity of that algorithm.
• Why Analyze Algorithms?
• When there are multiple alternative algorithms to solve a problem, we
analyze them and pick the one which is best suitable for our requirements.
Analysis of Algorithms
CSE&S Department, BUETK 2
Time Complexity
• Let f(n) = 15n2 + 45n be the time complexity of an algorithm. For
each value of n the function indicates the amount of time
required by the algorithm.
• So f(1) is the running time of the algorithm when the input has 1
data item.
• f(100) is the running time of the algorithm when the input has 100
data items, and so on.

Analysis of Algorithms
CSE&S Department, BUETK 3
Question
• Let f(n) = 10n2 + 5n be the time complexity of
an algorithm, calculate the running time of the
algorithm when input has 20 data items.

Analysis of Algorithms
CSE&S Department, BUETK 4
Time Complexity
• Let f(n) = 10n2 + 5n be the time complexity of an algorithm,
calculate the running time of the algorithm when input has 20
data items.
• Solution:
As from question we get n=20; put 20 in the function to gets the
running time of algorithm
f(20)=10*202 + 5*20
=4000+100
=4100 Ans
Analysis of Algorithms
CSE&S Department, BUETK 5
Class Activity
• Let f(n) = 12n3 + 25n2 be the time complexity of an algorithm,
calculate the running time of the algorithm when input has 10
data items.

Analysis of Algorithms
CSE&S Department, BUETK 6
Question
• Suppose the time complexity of
• Algorithm A is 3n2 + 2n + log n + 1/(4n)
• Algorithm B is 0.39n3 + n
Question: Which one will be Outperformed suppose there are 10 data sets?

Analysis of Algorithms
CSE&S Department, BUETK 7
Approximation of Analysis Results
• Suppose the time complexity of
• Algorithm A is 3n2 + 2n + log n + 1/(4n)
• Algorithm B is 0.39n3 + n
Question: Which one will be Outperformed suppose there are 10 data sets?
Answer:
Algorithm A (n=10) Algorithm B (n=10)
3n2 +2n+log n+ 1/(4n) 0.39n3 + n
=3(102)+2*10+log(10)+1/4(10) =0.39 * 103 +10
=3 * 100 + 20 * 1 + 1/40 =0.39*1000+10
=300 + 20 * 1 + 0.025 =400 Result
=321.025 Result
Algorithm A will outperform B

Analysis of Algorithms
CSE&S Department, BUETK 8
ANY QUESTION

Analysis of Algorithms
CSE&S Department, BUETK 9
Analysis of Algorithms
CSE&S Department, BUETK 10

You might also like