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

Lecture - Asymptotic Complexity and Abstract Data Types

The document discusses abstract data types and asymptotic analysis. It provides examples of different asymptotic notations like Big-O, Omega, and Theta notations. There is a tradeoff between time and space for algorithms - improvements in one aspect often lead to degradation in the other. Abstract data types define the essential operations on a data structure without considering implementation details. Common examples are stacks, queues, and lists.

Uploaded by

Chetan Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Lecture - Asymptotic Complexity and Abstract Data Types

The document discusses abstract data types and asymptotic analysis. It provides examples of different asymptotic notations like Big-O, Omega, and Theta notations. There is a tradeoff between time and space for algorithms - improvements in one aspect often lead to degradation in the other. Abstract data types define the essential operations on a data structure without considering implementation details. Common examples are stacks, queues, and lists.

Uploaded by

Chetan Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

UNIVERSITY INSTITUTE OF COMPUTING

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

• CO1: Apply appropriate data structure in designing programming solution


for the algorithm in relation to concept of classes.

03/09/2023
Asymptotic analysis
4

• Defines the mathematical foundation of its run-time performance.

• Conclude the best case, average case, and worst case.

• Efficiency depends on the amount of time, storage and other resources


required to execute the algorithm.

• The study of change in performance with the change in the order of the
input size.
Need for different notations
5

Usually, the time required by an algorithm falls under three types −

1. Best Case 

2. Average Case 

3. Worst Case
Types of notations
6

There are mainly three asymptotic notations:

• Big-O notation

• Omega notation

• Theta notation
Big-O notation
7

• If an algorithm process large amount of data, it is observed that there is a


certain term in the complexity function f(n) that grows the fastest. So any
other term or terms that do not substantially contribute to the function’s
magnitude should be eliminated from the function.
• The resulting function so calculated gives only an approximate time
complexity of the original function. However, this approximation is close to
the original, especially for the function that process large amount of data.
• This measure of time complexity of an algorithm where we disregard certain
terms of a function to express the efficiency of algorithm is call Asymptotic
Complexity.
Big-O notation
8

• Measures the performance by providing the order of growth of the function.

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

• Big O notation is the most commonly used notation for specifying


Asymptotic Complexity.
• If we have an algorithm f(n)=n^2+3n+10 then
• Big O notation will be expressed as O(n^2), i.e order of n^2.
• If f(n)=5n^3+3n^2+20n +100 then its big O notation will be expressed
asO(n^3).
Big-O notation
11

[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

• It determines what is the fastest time that an algorithm can run.

f(n) = Ω (g(n)) as f(n)

• f(n)>=c.g(n) for all n≥n0 and c>0

[1]
Omega notation
14

If f(n) = 2n+3, g(n) = n,

Is f(n)= Ω (g(n))?

It must satisfy the condition: f(n)>=c.g(n)

we first replace f(n) by 2n+3 and g(n) by n.

2n+3>=c*n

Suppose c=1

2n+3>=n (This equation will be true for any value of n starting from 1).

Therefore, it is proved that g(n) is big omega of 2n+3 function.


Omega notation
15
Theta Notation (Θ-notation)

16

• If a function is bounded both above and below then equality must be


indicated. We have seen Big-O notation and Big-Omega notation provides
upper and lower bound of a function. If f(n) is of order of g(n) i.e
f(n)=O(g(n)) and f(n) is omega of g(n) i.e f(n)= Ω(g(n)) then f(n) is theta of
g(n).
• This is represented as f(n)= Θ(g(n))
• Example:f(n)=2n2+3n+10
17

• 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

• The theta notation mainly describes the average case scenarios.


Let f(n) and g(n) be the functions of n where n is the steps required to execute
the program then:
f(n)= θg(n)
• The above condition is satisfied only if when
c1.g(n)<=f(n)<=c2.g(n)

[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

• There are many choices of algorithms available to solve a particular


problem. Some of them are extremely time efficient.
• The best algorithm used to solve a problem is the one that requires less time
to complete and takes less space in the memory when implemented.
• But it is not possible to achieve both these aspects as improvement in one
aspect leads to degradation in other.
• This means that some algorithms take large space in memory but arrive at a
solution quickly whereas other requires less space in memory but arrives at
a solution slowly.
• Thus one aspect of algorithm has to be compromised at the cost of other.
22

• Thus there exists a time space tradeoff among the algorithms.


• While solving a problem where time is critical, we choose an algorithm that
requires less time to complete when implemented at the cost of more
memory.
• On the other hand if space is critical while solving a problem then we
choose an algorithm that consumes less space when implemented in
memory at the cost of more time.
Abstract Data types
23

• Abstract data type (ADT) is a concept or model of a data type. 


• It is a way of looking at a data structure , focusing on what it can do
rather than how it can be done.
• A stack is the most common example of abstract data type that can be
implemented either using an array or linked list.
• No matter how the stack is implemented, what is important in a stack
is the push and pop operations and how they are used rather than
underlying mechanism to implement these operations.
• This demonstrates the abstract nature of stack as user can simply use
the push and pop operations without being concerned about stack
internal representation or internal logic of push and pop operations.
24

• 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

• A list is an ordered collection of the same data type. 

[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

• Stack is a linear ADT, with restrictions in inserting and deleting


elements from the same end. 

[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

• What is complexity? Describe different notations to represent it.


• Explain the different types of complexities.
• Throw light on Abstract data types.

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

You might also like