100% found this document useful (1 vote)
648 views45 pages

11-Best Case, Worst Case, Average Case Analysis-08-08-2022

1) Asymptotic notations are used to represent the complexity of algorithms as input size increases. The main types are Big-O (worst case), Omega (best case), and Theta (average case). 2) Big-O notation provides an upper bound and describes worst case complexity such as O(1) for constant time, O(log n) for logarithmic time, O(n) for linear time, and O(n^2) for quadratic time. 3) Omega notation provides a lower bound and describes best case complexity. Theta notation represents average case complexity.

Uploaded by

Ishank
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
100% found this document useful (1 vote)
648 views45 pages

11-Best Case, Worst Case, Average Case Analysis-08-08-2022

1) Asymptotic notations are used to represent the complexity of algorithms as input size increases. The main types are Big-O (worst case), Omega (best case), and Theta (average case). 2) Big-O notation provides an upper bound and describes worst case complexity such as O(1) for constant time, O(log n) for logarithmic time, O(n) for linear time, and O(n^2) for quadratic time. 3) Omega notation provides a lower bound and describes best case complexity. Theta notation represents average case complexity.

Uploaded by

Ishank
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/ 45

Asymptotic Notations

Dr. T. JOSHVA DEVADAS


VIT UNIVERSITY
Asymptotic Notations
Analysis of Algorithms
• An algorithm is a finite set of precise instructions
for performing a computation or for solving a
problem.
• What is the goal of analysis of algorithms?
– To compare algorithms mainly in terms of running time
but also in terms of other factors (e.g., memory
requirements, programmer's effort etc.)
• What do we mean by running time analysis?
– Determine how running time increases as the size of
the problem increases.
3
Input Size

• Input size (number of elements in the input)


– size of an array
– polynomial degree

– # of elements in a matrix
– # of bits in the binary representation of the input
– vertices and edges in a graph

4
Asymptotic Notations
• Asymptotic Notations are the expressions that
are used to represent the complexity of an
algorithm.
• There are three types of analysis that we
perform on a particular algorithm.

1 < log n <

5
Types of Analysis
• Best Case: In which we analyse the performance
of an algorithm for the input, for which the
algorithm takes less time or space.
• Worst Case: In which we analyse the
performance of an algorithm for the input, for
which the algorithm takes long time or space.
• Average Case: In which we analyse the
performance of an algorithm for the input, for
which the algorithm takes time or space that lies
between best and worst case.
6
Types of Analysis
• Worst case
– Provides an upper bound on running time
– An absolute guarantee that the algorithm would not run longer, no
matter what the inputs are
• Best case
– Provides a lower bound on running time
– Input is the one for which the algorithm runs the fastest

• Average case
– Provides a prediction about the running time
– Assumes that the input is random
7
Types of Data Structure Asymptotic Notation

1. Big-O Notation (Ο) – Big O notation


specifically describes worst case scenario.

2. Omega Notation (Ω) – Omega(Ω) notation


specifically describes best case scenario.

3. Theta Notation (θ) – This notation represents


the average complexity of an algorithm.

8
Big-O Notation (Ο)
Big O notation specifically describes worst case scenario. It
represents the upper bound running time complexity of an
algorithm.
Lets take few examples to understand how we represent the time
and space complexity using Big O notation.
O(1)
Big O notation O(1) represents the complexity of an algorithm that
always execute in same time or space regardless of the input data.
O(1) example
The following step will always execute in same time(or space)
regardless of the size of input data.
Accessing array index(int num = arr[5])

9
• O(n)
• Big O notation O(N) represents the complexity of an
algorithm, whose performance will grow linearly (in
direct proportion) to the size of the input data.
• O(n) example
The execution time will depend on the size of array.
When the size of the array increases, the execution
time will also increase in the same proportion
(linearly) Traversing an array

10
O(n^2)
Big O notation O(n^2) represents the complexity of
an algorithm, whose performance is directly
proportional to the square of the size of the input
data.
• O(n^2) example
Traversing a 2D array
• Other examples: Bubble sort, insertion sort and
selection sort algorithms
11
Similarly there are other Big O notations such as:
logarithmic growth O(log n), log-linear growth
O(n log n), exponential growth O(2^n) and factorial
growth O(n!).
The following diagram shows the comparative
performance of algorithms denoted by these
notations

12
Algorithmic Examples of Runtime Analysis:
Some of the examples of all those types of algorithms (in worst-case scenarios) are
mentioned below:

• Logarithmic algorithm – O(logn) – Binary Search


• Linear algorithm – O(n) – Linear Search
• Superlinear algorithm – O(nlogn) – Heap and Merge Sort
• Polynomial algorithm – O(n^c) – Strassen’s Matrix
• Multiplication, Bubble Sort, Selection Sort, Insertion Sort,
Bucket Sort
• Exponential algorithm – O(c^n) – Tower of Hanoi
▪ Factorial algorithm – O(n!) – Determinant Expansion by
Minors, Brute force Search algorithm for Traveling
Salesman Problem.
Asymptotic notations
• O-notation

16
BIG Oh
Big O Notation
Omega Notation ( - notation)
Asymptotic notations (cont.)
•  - notation

(g(n)) is the set of functions


with larger or same order of
growth as g(n)

22
Θ Notation
Asymptotic notations (cont.)
• -notation

(g(n)) is the set of functions


with the same order of growth as
g(n)

27
Basic asymptotic efficiency classes
1 constant

log n logarithmic

n linear

n log n n-log-n

n2 quadratic

n3 cubic

2n exponential

n! factorial
constant

You might also like