You are on page 1of 27

1

ary 18, 2024


Thursday, Janu
gorithm
Lahore Garrison University
CSC354-Design and Analysis of Algorithms
Week-2 Lecture-4

Analysis of Al
Semester-# fall 2019
Prepared by:

Awais Salman Qazi


2
Instructor Contact Details

 Name: Awais Salman Qazi


 Course Instructor: Design and Analysis of Algorithms
 Credit Hours: 3
 Office Location: CS-Faculty Office, 2nd Floor New Building
 Email: awais.salman@lgu.edu.pk
 Visiting Hours: Friday 8am-10am. Also after class. Students can also walk in if I am free
 phone calls are not allowed

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
3
Previous Lecture Summary

 Algorithm Analysis
 Efficiency Measurement
 Algorithm Correctness

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
4
Today’s Lecture Summary

 Algorithm Analysis
 Efficiency Measurement
 Algorithm Efficiency

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
5
Algorithm Analysis

While designing an algorithm we have to take care of two aspects:


1. Algorithm Correctness: Algorithm must give desired output within finite time.
2. Algorithm Efficiency : Algorithms must use minimum resources while executing on a
machine.

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
6

Efficiency Analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
7

What is efficiency analysis?


 Measuring time efficiency
 Best case, worst case and average case analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
8
Efficiency Analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
9
Efficiency Analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
10
Efficiency Analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
11
Efficiency Analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
12
Efficiency Analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
13
Space and time trade off

 Often we have to make a compromise between space efficiency and time efficiency
 Example: adjacency matrix vs adjacency list for graph representation.
 A sparse graph can be represented by an adjacency matrix which would be time efficient for
traversing an edge but it will be at the cost of space
 A sparse graph can be represented by an adjacency list which would be space efficient and but it
would take longer time for traversing the edges.

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
14
How can be time efficiency measured?

Our efficiency measure for running time must be independent of


 machine
 programming language
 Programmer
Running time is a function of input size denoted by T(n) where n is input size.

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
15


RAM: Computational Model

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
16

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
17
Example1: running time

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
18
Example1: running time

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
19
Example2: running time

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
20
Example2: running time

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
21
Example3: running time

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
22
Example3: running time

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
23
Best-case analysis and worst-case analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
24
Best-case analysis and worst-case analysis

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
25

 FURTHER DISCUSSION

NEXT WEEK …………….

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
26

Q &A

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024
27
References

 These lecture notes were taken from following source:

 Introduction to Algorithms 2nd ,Cormen, Leiserson, Rivest and Stein, The


MIT Press, 2001.

Lahore Garrison University Analysis of Thursday, Jan


Algorithm uary 18, 2024

You might also like