Lecture - Asymptotic Complexity and Abstract Data Types
Lecture - Asymptotic Complexity and Abstract Data Types
BCA/BSC CS
DATA STRUCTURES
(22CAT-211/22SCT-211/22CAT231)
1
Content
2
Chapter 1 (Unit I)
• Lecture1.1.3:Aymptotic complexity and abstract data types
Asymptotic Notations
Time Space Trade Off
Abstract data types
Objectives/Outcomes
3
03/09/2023
Asymptotic analysis
4
• The study of change in performance with the change in the order of the
input size.
Need for different notations
5
1. Best Case
2. Average Case
3. Worst Case
Types of notations
6
• Big-O notation
• Omega notation
• Theta notation
Big-O notation
7
O(g(n)) = { f(n): there exist positive constants c and n0 such that 0 ≤ f(n) ≤ c.g(n) for all n ≥ n0 }
[1]
Big-O notation
9
Example 1: f(n)= n^2+ 3n +10
As the value of n grows the two terms 3n and 10 are so dominant as their contribution
to the function value is less significant. However, for large value of n, the value of f(n)
mainly depends upon n^2.
thus for processing large amount of data, we only concerned about a dominant term in
the complexity function i.e the term with the largest order of magnitude n^2
We don’t need to find the exact time complexity but only need to find the dominant
term that determines the order of magnitude of function.
Big O notation also known as Big Oh notation and was introduced by 1894 by Paul
Bachmann.
The main aim of this notation is to identify the dominant term in finding the time
complexity of an algorithm.
[1]
10
[1]
Omega Notation (Ω-notation)
12
• The omega notation is used when the function defines a lower bound for the
function f(n). It can formally be defined as
f(n)=Ω(g(n))
Example: f(n)= 2n^2-5n+10
f(n)= Ω(n)
Omega Notation (Ω-notation)
13
[1]
Omega notation
14
Is f(n)= Ω (g(n))?
2n+3>=c*n
Suppose c=1
2n+3>=n (This equation will be true for any value of n starting from 1).
16
• Theta notation encloses the function from above and below. Since it
represents the upper and the lower bound of the running time of an
algorithm, it is used for analyzing the average-case complexity of an
algorithm.
Theta Notation (Θ-notation)
18
[1]
Theta Notation (Θ-notation)
19
f(n)=2n2+n, g(n)=n2
c1.g(n)<=f(n)<=c2.g(n) Replace g(n) by n and f(n) by 2n+3
c1.n <=2n+3<=c2.n
if c1=1, c2=5, n=1
1*1 <=2*1+3 <=5*1
1 <= 5 <= 5 // for n=1, it satisfies the condition c1.g(n)<=f(n)<=c2.g(n)
If n=2
1*2<=2*2+3<=5*2
2<=7<=10 // for n=2, it satisfies the condition c1.g(n)<=f(n)<=c2.g(n)
[1]
Common Asymptotic Notations
20
[1]
Time Space Trade Off
21
• To understand the Abstract Data Type divide it into two terms: Data Type
and Abstract.
Datatype:
• While dealing with basic data type, we concentrate on set of possible values
that can be stored on data item and list of all permissible operations that can
be applied on it. Eg. The datatype int in C has set of values -32768 to 32767
and allowable operations on these values are +,-,/,%,etc. the possible
operations on datatype are an inseparable part of identity. Understanding the
data type means what operations can be performed on it.
• The datatype consists of two parts: a) Values b) Operations
25
• Abstract
• By the term abstract we identify the essential features without considering
detailed specification or implementation.
• There are several examples of ADTs and stack and queues are common
among these.
• ADTs has two parts a) a particular data structure and b) operations applied
on data structure
Types of ADT
26
[4]
List ADT
27
[4]
List ADT Functions
28
1. get()
2. insert()
3. remove()
4. removeAt()
5. replace()
6. size()
7. isEmpty()
8. isFull()
[4]
Stack ADT
29
[4]
Stack ADT Functions
30
1. push()
2. pop()
3. peek()
4. size()
5. isEmpty()
6. isFull()
[4]
Queue ADT
31
• A queue is a linear ADT with the restriction that insertion can be performed
at one end and deletion at another.
[4]
Queue ADT Functions
32
1. enqueue()
2. dequeue()
3. peek()
4. size()
5. isEmpty()
6. isFull()
[4]
Frequently asked questions
33
03/09/2023
REFERENCES
34
[1] https://www.programiz.com/dsa/asymptotic-notations
[2]
https://www.geeksforgeeks.org/analysis-of-algorithms-set-3asymptotic-notati
ons/
[3] https://www.tutorialspoint.com/Asymptotic-Notations
[4] https://www.baeldung.com/cs/adt
03/09/2023
THANK YOU