0% found this document useful (0 votes)
43 views

Design & Analysis of Algorithms (CS-3444) : Husnain Iqbal

The document outlines an agenda for the course "Design & Analysis of Algorithms" which includes discussing textbooks and resources, grading policies, and an introduction to key concepts like the reasons for studying algorithms, what algorithms are, analyzing time and space complexity, different types of time complexity functions, and how to calculate the running time of algorithms.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Design & Analysis of Algorithms (CS-3444) : Husnain Iqbal

The document outlines an agenda for the course "Design & Analysis of Algorithms" which includes discussing textbooks and resources, grading policies, and an introduction to key concepts like the reasons for studying algorithms, what algorithms are, analyzing time and space complexity, different types of time complexity functions, and how to calculate the running time of algorithms.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Design & Analysis of Algorithms

(CS-3444 )

Husnain Iqbal
Agenda
• Textbook and Other Resources
• Tentative Grading Distribution and Policy
• Introduction to Algorithms:
• Why we study Algorithms?
• What is an Algorithm?
• Time Complexity & Space Complexity
• Various types of Time Complexity
• How to calculate Running Time of an Algorithm?
• Various Functions in asymptotic notation
Textbook and Other Resources

• Text Book:
1. T. H. Cormen, C. E. Leiserson and R. L. Rivest, Introduction to Algorithms, (3rd
Edition)

• Other Resources:
1. Algorithms –Sanjoy Das Gupta, Christos Papadimitriou, Umesh Vazirani
2. Internet Resources
Tentative Grading
Distribution and Policy
Why we study “Algorithms”?
• Because they are applied to a vast variety of fields in Computer Science
including:
• Operating Systems
• Artificial Intelligence
• Machine Learning
• Data Science
• Data Mining
• Information Retrieval etc.
What is an Algorithm?
• Definition:
 “A step by step procedure to solve a problem” Divide x by y
• Example: Calculate the x % y; where x and y are
user-inputs Store answer and the
remainder values

Return the remainder


So we have solved our problem. Is it enough?
What is an Algorithm?
• Example-2:
 We have an array containing 100000 names and we want to find a name ‘Muhammad Ali’
from it.
 Suppose we have an algorithm which takes 1 millisecond for one name comparison. At
worst, how much time will it take to find a name in that array?
 Worst time to find a name = 100000 * 10-3 = 100 seconds
• So we need those algorithms which take lesser time to solve our problems
• Similar is the case with space as our Computer Machines have limited space to
work on; so we prefer those algorithms which consume lesser Memory.
Time and Space Complexity

Time Complexity of an Algorithm Space Complexity of an Algorithm


• The amount of time taken by • The amount of space or memory
an algorithm to run as a function taken by an algorithm to run as a
of the length of the input i.e. f(n) function of the length of the input
where n is the input size i.e. f(n) where n is the input size
Types of Time Complexity
• Three types of complexity exists when analyzing algorithm performance.
1. Worst-case time complexity: Maximum running time for an algorithm O (f(n))
2. Best-case time complexity: Minimum running time for an algorithm Ω (f(n))
3. Average-case time complexity: Average running time for an algorithm 𝜽 (𝒇(𝒏))
• However, only worst-case complexity has found to be useful.
Types of Time Complexity
• Example: Given an Array i.e. int [ ] digits = {5, 13, 2, 40, 11, 17, 39, 20, 1, 9}
perform find(9) and find(5)
• find(9) will take 10 comparisons. Worst-Cast
• Find(5) will take just 1 comparison. Best Cast
• However, average case will take average of both best and worst case times
which is 5.5 i.e. we can consider either 5 or 6 as Average case time.
How to calculate Running Time of an
Algorithm?
• Running time of an Algorithm does not mean time in seconds/minutes/
hours/days /months etc.
• The running time of an algorithm for a specific input, say N, depends on the
total number of operations executed.
• The greater the number of operations, the longer the running time of an
algorithm.
• So count the total number of operations performed in an algorithm in order
to estimate the running time of it.
How to calculate Running Time of an
Algorithm?
Total number of operations = 1 + 1 + 1
+ (N+1) + N + N + 1 + 1
Total number of operations = 3N + 6
Time Complexity: O(3N + 6) ≈ O (N)
Various Functions in asymptotic notation
• O(1) - Constant Time:
• O(log(n)) - Logarithmic Time:
• O(N) - Linear Time:
• O(Nc) – Polynomial Time: O(N²) - Quadratic Time | O(N3) - Quadratic Time:
• O(cN) - Exponential Time: O(c2) | O(c3) | O(c4)
• O(N!) – Factorial Time
• Note: N is the input size while c represents some constant here

You might also like