DS Unit-1 Handouts
DS Unit-1 Handouts
11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
Data Structures
• Pre-requisites:
1. Basic knowledge of one programming language (C, C++, C#, Java, JavaScript,
Python2/3, Ruby, Scala)
2. Basic knowledge of common programming concepts, including control structures,
loops, and recursion
3. Basic knowledge of mathematics, including proof by induction and contradiction
• Course Outcomes (Cos):
1. To provide the knowledge of basic data structures and their implementations.
2. To understand importance of data structures in context of writing efficient
programs.
3. To develop skills to apply appropriate data structures in problem solving.
**Study material prepared by Dr. Vaishali Joshi
Syllabus – Unit 1
Introduction to
Algorithms and Data structures
Concepts and design of algorithm ,Various notations used in
representing complexities of algorithms, Introduction to data structures
and their utilities Types of data structures ,Data structure operation
1
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
Introduction
SYMBIOSIS UNIVERSITY
SYMBIOSIS
OF APPLIED
UNIVERSITY
SCIENCES,
OFINDORE
APPLIEDBy
SCIENCES,
Dr. Vaishali
INDORE
Joshi By Dr. Vaishali Joshi 4
Algorithm: Definition
Input Output
Algorithm
2
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
• Problem definition
• What task has to be done.
• Calculation of mean, square root, shortest path etc.
• Algorithm design
• Writing pseudo code, drawing flow chart etc. (Decision of algorithm design model like Divide
& Conquer, Dynamic Programming, Greedy etc.)
• Algorithm analysis
• Analysis of time and space required to run the algorithm.
• Implementation
• Writing a program
• Testing
• Testing of the output
**Study material prepared by Dr. Vaishali Joshi
Properties of Algorithm
Note: A procedure that has all the characteristics of an algorithm except finiteness is called
**Study material prepared by Dr. Vaishali Joshi
computational methods.
SYMBIOSIS UNIVERSITY OF APPLIED SCIENCES, INDORE By Dr. Vaishali Joshi 8
Characteristics of Algorithm
• Input: An algorithm has zero or more input
• Output: An algorithm has one or more output.
• Definiteness: Each instruction must be clear and unambiguous.
• Effectiveness: An algorithm must be effective in such a way that its
operations are sufficiently basic and feasible.
• Termination: It must terminate with the production of correct output
from the given input
**Study material prepared by Dr. Vaishali Joshi
3
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
Example of an Algorithm
Algorithm analysis
4
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
• Time
• Space
• Correctness of an algorithm
Algorithm Analysis
Asymptotic notations are used to represent the Complexity is represented in terms of watch
complexity in terms of time and space functions time ( milli second, nano second etc.) and
**Study material prepared by Dr. Vaishali Joshi
bits/bytes (for space complexity)
SYMBIOSIS UNIVERSITY OF APPLIED SCIENCES, INDORE By Dr. Vaishali Joshi 14
Algorithm Analysis
Algorithm analysis
5
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
6
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
Space Complexity
• Space complexity of an algorithm represents the amount of memory
space needed by the algorithm in its life cycle.
• The space complexity of an algorithm or a computer program is the
amount of memory space required to solve an instance of
the computational problem as a function of characteristics of the
input. It is the memory required by an algorithm until it executes
completely.
• Space needed by an algorithm is equal to the sum of the following
two components – Fixed and variable
**Study material prepared by Dr. Vaishali Joshi
Space Complexity
• A fixed part that is a space required to store certain data and
variables (i.e. simple variables and constants, program size etc.), that
are not dependent of the size of the problem.
• A variable part is a space required by variables, whose size is totally
dependent on the size of the problem. For example, recursion stack
space, dynamic memory allocation etc.
• Space complexity S(p) of any algorithm p is S(p) = A + S(I) Where A is
treated as the fixed part and S(I) is treated as the variable part of the
algorithm which depends on instance characteristic I.
**Study material prepared by Dr. Vaishali Joshi
Space Complexity
Here we have three variables P, Q and R and one constant. Hence S(p) =
1+3. Now space is dependent on data types of given constant types and
variables and it will be multiplied accordingly.
7
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
Space Complexity
Auxiliary space: Space other than that consumed by the input.
We often speak of Auxiliary space (extra memory) needed, not counting the memory
needed to store the input itself.
Example:
int FindMax(int A[], int n)
{
int max=A[0];
for (int i=0;i<n;i++){
if(A[i]>max)
max=A[i];
}
return max;
}
**Study material prepared by Dr. Vaishali Joshi
• Observations:
• At n=10, Algorithm A looks bad.
• As n increases, the Algorithm A looks
better. (Why?)
• Regardless of the coefficients, there
will always be some value of n where an2 > bn.
• Even if the run time of Algorithm A were n + 10000, it would still be better
than Algorithm B for sufficiently large n.
• Conclusion: The coefficient and non-leading term do not affect the
order of growth for some sufficient large value of n.
The leading term is the term with the highest exponent.
**Study material prepared by Dr. Vaishali Joshi
8
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
The three most commonly used notations are Big O, Omega, and Theta.
• Big O notation (O): This notation provides an upper bound on the growth
rate of an algorithm’s running time or space usage. It represents the worst-
case scenario, i.e., the maximum amount of time or space an algorithm
may need to solve a problem. For example, if an algorithm’s running time is
O(n), then it means that the running time of the algorithm increases
linearly with the input size n or less.
• Omega notation (Ω): This notation provides a lower bound on the growth
rate of an algorithm’s running time or space usage. It represents the best-
case scenario, i.e., the minimum amount of time or space an algorithm
may need to solve a problem. For example, if an algorithm’s running time is
Ω(n), then it means that the running time of the algorithm increases
linearly with the input size n or more.
**Study material prepared by Dr. Vaishali Joshi
9
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
• Theta notation (Θ): This notation provides both an upper and lower
bound on the growth rate of an algorithm’s running time or space
usage. It represents the average-case scenario, i.e., the amount of
time or space an algorithm typically needs to solve a problem. For
example, if an algorithm’s running time is Θ(n), then it means that the
running time of the algorithm increases linearly with the input size n.
It is important to note that asymptotic notation does not provide an
exact running time or space usage for an algorithm, but rather a
description of how the algorithm scales with respect to input size. It is a
useful tool for comparing the efficiency of different algorithms and for
predicting how they will perform on large input sizes.
**Study material prepared by Dr. Vaishali Joshi
2. Big–OMEGA (Ω)
3. Big–THETA (Θ)
4. Little–OH (o)
5. Little–OMEGA (ω)
• Let f(n) and g(n) be two functions from set of integers to real
numbers , f:Z→R, then f(n) is O(g(n)) or f(n) = O(g(n)) iff
0≤𝑓 𝑛 ≤𝐶∗𝑔 𝑛 ∀𝑛 ≥ 𝑛0
Where, C and n0 are any positive real constants Big Oh notation
always gives
Upper Bound
10
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
• Let f(n)= n3+3n+5 and g(n)= n3. If f(n)=O(g(n)) then find C and n0.
Let f(n)=n2+3n+5. if f(n)=O(g(n)) then what could be the possible values for
g(n)?
• Let f(n) and g(n) be two functions from set of integers to real numbers , f:Z→R, then
f(n) is Ω(g(n)) or f(n) = Ω(g(n)) iff
0 ≤ 𝐶 ∗ 𝑔 𝑛 ≤ 𝑓(𝑛) ∀𝑛 ≥ 𝑛0
Where, C and n0 are any positive real constants Big Omega
notation always
gives Lower Bound
11
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
• Let f(n) and g(n) be two functions from set of integers to real
numbers , f:Z→R, then f(n) is Θ (g(n)) or f(n) = Θ (g(n)) iff
0 ≤ 𝐶1 ∗ 𝑔 𝑛 ≤ 𝑓 𝑛 ≤ 𝐶2 ∗ 𝑔(𝑛) ∀𝑛 ≥ 𝑛0
Where, C and n0 are any positive real constants Big Theta notation
always gives tight
bound
12
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
• Let f(n)= n+5 and f(n) ∈ Θ (n). Calculate C1, C2 and n0.
13
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
1 < 𝑙𝑜𝑔𝑛 < 𝑛 < 𝑛 < 𝑛𝑙𝑜𝑔𝑛 < 𝑛 < 𝑛 … … . < 2 < 3 … … .
< 𝑛
Let f(n)=n2+5 then f(n)=O(n2) (How?) and f(n)=Ω (n2) (How?) that implies f(n)=
Θ (n2).
**Study material prepared by Dr. Vaishali Joshi
Mathematically, if
𝑓(𝑛)
lim =0
→ 𝑔(𝑛)
14
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
Mathematically, if
𝑓(𝑛)
lim =∞
→ 𝑔(𝑛)
15
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
16
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
Commonly used ADTs include: Linked Lists, Stacks, Queues, Priority Queues, Binary
Trees, Dictionaries, Disjoint Sets (Union and Find), Hash Tables, Graphs, and many
others.
17
Data Structures,Unit-1 (Notes prepared by Dr. 11-01-2025
Vaishali Joshi, Associate Professor – SCSIT,
SUAS, Indore)
• Notion of Algorithm
• Properties of Algorithm
• Importance of Analysis of Algorithm
• Time and Space Complexities
• Asymptotic Notations (O,Ɵ,Ω,o, and ω)
• Variables and Data Types
• Introduction to Data Structures & their utilization
• Abstract Data type
• Data Structure Operations
**Study material prepared by Dr. Vaishali Joshi
Thank you
Doubts??
**Study material prepared by Dr. Vaishali Joshi
18