0% found this document useful (0 votes)
9 views14 pages

Lecture-2 - Computational Complexity and Asymptotic Notation

The document discusses computational complexity in algorithms, focusing on time and space complexity as key resources required for execution. It outlines the three cases of complexity analysis: best, average, and worst case, along with asymptotic notations such as Big-O, Big-Ω, and Big-θ for representing these cases. The importance of understanding these complexities is emphasized for algorithm design and analysis.

Uploaded by

ovikhan753
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views14 pages

Lecture-2 - Computational Complexity and Asymptotic Notation

The document discusses computational complexity in algorithms, focusing on time and space complexity as key resources required for execution. It outlines the three cases of complexity analysis: best, average, and worst case, along with asymptotic notations such as Big-O, Big-Ω, and Big-θ for representing these cases. The importance of understanding these complexities is emphasized for algorithm design and analysis.

Uploaded by

ovikhan753
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

CSE214: Algorithms

Computational complexity

1
Today’s Contents
• Computational complexity
• Asymptotic Notation
• Why Complexity Analysis is needed?

2
Computational complexity
▪ In computer science, the computational complexity or
simply complexity of an algorithm is the amount of
resources required to run it.

▪ The study of the complexity of problems is called


computational complexity theory.

▪ Particular focus is given to Time and Memory


requirements.

▪ Amount of resources required to run an algorithm


generally varies with the size of the input 3
Complexity Analysis of Algorithm

1. Time Complexity
2. Space Complexity

4
Complexity Analysis of Algorithm

1. Time Complexity
Time complexity is generally expressed as the number of
required elementary operations on an input of size n, where
elementary operations are assumed to take a constant amount of
time on a given computer and change only by a constant factor
when run on a different computer.

2. Space Complexity
Space complexity is generally expressed as the amount of
memory required by an algorithm on an input of size n.
5
Understanding of Time and Space Complexity
Design an algorithm to add two numbers and display the result

Algo-1: Algo-2:
1. START 1. START
2. declare three integers a, b & c 2. declare three integers a & b
3. Input in a & b 3. Input in a & b
4. c a+b 4. print a+b
5. print c 5. STOP
6. STOP

Time = 6 sec Time = 5 sec


6
Space = 12 Bytes Space = 8 Bytes
Three Cases of Complexity Analysis
Usually, complexity analysis of an algorithm falls under
three types −

1. Best Case Minimum number of steps required for


program execution.

2. Average Case Average number of steps required for


program execution.

3. Worst Case Maximum number of steps required for


program execution.

7
Asymptotic Notations
Following are the commonly used asymptotic notations to
calculate the running time complexity of an algorithm.

Used to represent the Worst case.


1. Big-O (oh) Notation

Used to represent the Best case


2. Big-Ω (Omega) Notation

3. Big-θ (Theta) Notation Used to represent the Average case

8
Understanding of Three cases
and Asymptotic Notation

▪ Example: 01
Search an element in an Array.

5 6 3 8 1 31

▪ Best case = Ω (1)


▪ Worst case = O (n)
▪ Average case = θ (n/2) = θ (n)
9
Understanding of Three cases
and Asymptotic Notation

▪ Example: 02
Sort the element in an Array.

5 6 7 8 10 31

▪ Best case = Ω (n) Already Sorted Array


▪ Worst case =
▪ Average case =
10
Understanding of Three cases
and Asymptotic Notation

▪ Example: 02
Sort the element in an Array.

5 6 3 8 1 31

▪ Best case = Ω (n)


▪ Worst case = O (n * n) = O (n2)
Unsorted Array
▪ Average case = θ (n * n) = O (n2)
11
Best, worst and average case

▪ It’s difficult to estimate the exact running time.


▪ We are usually interested in the order of growth of the
running time of an algorithm, not in the exact running
time.
• Best case depends on the input
• Average case is difficult to compute

• So we usually focus on worst case analysis


▪ Easier to compute
▪ Usually close to the actual running time
12
Some common rates of growth

Let n be the size of input to an algorithm, and k some


constant. The following are common rates of growth.

13
Thank you!

14

You might also like