0% found this document useful (0 votes)
12 views23 pages

document_1676338680430

The document provides an introduction to data structures, explaining their importance in efficient data storage and manipulation. It classifies data structures into simple and compound types, as well as linear and non-linear structures, and discusses operations performed on them. Additionally, it covers algorithms, their properties, analysis, and complexity, including asymptotic notations and time complexity classifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views23 pages

document_1676338680430

The document provides an introduction to data structures, explaining their importance in efficient data storage and manipulation. It classifies data structures into simple and compound types, as well as linear and non-linear structures, and discusses operations performed on them. Additionally, it covers algorithms, their properties, analysis, and complexity, including asymptotic notations and time complexity classifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

INTRODUCTION TO DATA STRUCTURES

Hitesh Gupta
Assistant Professor Department of CSE
LNCT BHOPAL
Introduction to Data Structures
• A data structure is a way of storing data in a
computer so that it can be used efficiently and
it will allow the most efficient algorithm to be
used.
• A data structure should be seen as a logical
concept that must address two fundamental
concerns.
I. First, how the data will be stored, and
II. Second, what operations will be performed on it.
2
Classification of Data Structures
• Data structures can be classified as
i. Simple data structure
ii. Compound data structure
iii. Linear data structure
iv. Non linear data structure

Fig. Classification of Data Structures 3


Simple and Compound Data Structures

• Simple Data Structure: Simple data structure can be constructed


with the help of primitive data structure. A primitive data structure
used to represent the standard data types of any one of the
computer languages. Variables, arrays, pointers, structures, unions,
etc. are examples of primitive data structures.
• Compound Data structure: Compound data structure can be
constructed with the help of any one of the primitive data structure
and it is having a specific functionality. It can be designed by user. It
can be classified as
i. Linear data structure
ii. Non-linear data structure

5
Linear and Non-linear Data Structures

• Linear Data Structure: Linear data structures can be


constructed as a continuous arrangement of data
elements in the memory. It can be constructed by
using array data type. In the linear Data Structures the
relationship of adjacency is maintained between the
data elements.

Non Linear Data Structure: Non-linear data


structure can can be constructed as a collection of
randomly distributed set of data item joined together
by using a special pointer (tag). In non-linear Data
structure the relationship of adjacency is not
maintained between the data items.
5
Operations on Data Structures

i. Add an element
ii. Delete an element
iii. Traverse
iv. Sort the list of elements
v. Search for a data element

6
Abstract Data Type
• An abstract data type, sometimes abbreviated
ADT, is a logical description of how we view
the data and the operations that are allowed
without regard to how they will be
implemented.
• By providing this level of abstraction, we are
creating an encapsulation around the data. The
idea is that by encapsulating the details of the
implementation, we are hiding them from the
user‘s view. This is called information hiding.
7
Algorithm Definition
• An Algorithm may be defined as a finite
sequence of instructions each of which has a clear
meaning and can be performed with a finite
amount of effort in a finite length of time.
• The word algorithm originates from the Arabic
word Algorism which is linked to the name of the
Arabic Mathematician AI Khwarizmi.
• AI Khwarizmi is considered to be the first
algorithm designer for adding numbers.
8
Structure of an Algorithm
• An algorithm has the following
structure:
– Input Step

– Assignment Step

– Decision Step

– Repetitive Step

– Output Step

9
Properties of an Algorithm
• Finiteness:- An algorithm must terminate after
finite number of steps.
• Definiteness:-The steps of the algorithm must be
precisely defined.
• Generality:- An algorithm must be generic
enough to solve all problems of a particular
class.
• Effectiveness:- The operations of the algorithm
must be basic enough to be put down on pencil
and paper.
10
Input-Output:- The algorithm must have certain
initial and precise inputs, and outputs that may be
generated both at its intermediate and final steps
Algorithm Analysis and Complexity
• The performances of algorithms can be
measured on the scales of Time and Space.
• The Time Complexity of an algorithm or a
program is a function of the running time of
the algorithm or a program.
• The Space Complexity of an algorithm or a
program is a function of the space needed by
the algorithm or program to run to completion.

12
Algorithm Analysis and Complexity
• The Time Complexity of an algorithm can be computed
either by an
– Empirical or Posteriori Testing
– Theoretical or Apriori Approach
• The Empirical or Posteriori Testing approach calls for
implementing the complete algorithm and executes
them on a computer for various instances of the
problem.
• The Theoretical or Apriori Approach calls for
mathematically determining the resources such as time
and space needed by the algorithm, as a function of
parameter related to the instances of the problem
considered.
13
Algorithm Analysis and Complexity
• Apriori analysis computed the efficiency of the
program as a function of the total frequency
count of the statements comprising the
program.
• Example: Let us estimate the frequency count
of the statement x = x+2 occurring in the
following three program segments A, B and C.

14
Total Frequency Count of Program Segment A

• Program Statements • Frequency Count


..…………………
x = x+ 2 1
….……………….
Total Frequency Count 1

Time Complexity of Program Segment A is O(1).

15
Total Frequency Count of Program Segment B

• Program Statements • Frequency Count


..…………………
for k = 1 to n do (n+1)
x = x+ 2; n

….………………. ……………………
Total Frequency Count 2n+1

Time Complexity of Program Segment B is O(n).


16
Total Frequency Count of Program Segment C

• Program Statements • Frequency Count


..…………………
for j = 1 to n do (n+1)
for k = 1 to n do (n+1)n
x = x+ 2;
end n2
end n2
….…………… n
Total Frequency Count….
3n2+3n+1

Time Complexity of Program Segment C is O(n2).


17
Asymptotic Notations
• Big oh(O): f(n) = O(g(n)) ( read as f of n is big
oh of g of n), if there exists a positive integer
n0 and a positive number c such that |f(n)| ≤ c
|g(n)| for all n ≥ n0.
f(n) g(n)
16n3 + 45n2 +12n n3 f(n) = O(n3 )

34n – 40 n f(n) = O(n)


50 1 f(n) = O(1)

• Here g(n) is the upper bound of the function f(n).

18
Asymptotic Notations
• Omega(Ω): f(n) = Ω(g(n)) ( read as f of n is
omega of g of n), if there exists a positive
integer n0 and a positive number c such that
|f(n)| ≥ c |g(n)| for all n ≥ n0.
f(n) g(n)

16n3 + 8n2 +2 n3 f(n) = Ω (n3 )

24n +9 n f(n) = Ω (n)

Here g(n) is the lower bound of the function f(n).


19
Asymptotic Notations
• Theta(Θ): f(n) = Θ(g(n)) (read as f of n is theta
of g of n), if there exists a positive integer n0
and two positive constants c1 and c2 such that
c1 |g(n)| ≤ |f(n)| ≤ c2 |g(n)| for all n ≥ n0.
f(n) g(n)
16n3 + 30n2 – 90 n2 f(n) = Θ(n2 )

7. 2n + 30n 2n f(n) = Θ (2n)

• The function g(n) is both an upper bound and a


lower bound for the function f(n) for all values
of n, n ≥ n0 20
Asymptotic Notations
• Little oh(o): f(n) = O(g(n)) ( read as f of n is
little oh of g of n), if f(n) = O(g(n)) and f(n) ≠
Ω(g(n)).
f(n) g(n)
18n + 9 n2 f(n) = o(n2) since f(n) = O(n2 )
and f(n) ≠ Ω(n2 ) however f(n)
≠ O(n).

21
Time
Complexity
Complexity Notation Description
Constant O(1) Constant number of operations, not depending on the
input data size.
Logarithmic O(logn) Number of operations proportional of log(n) where n
is the size of the input data.
Linear O(n) Number of operations proportional to the input data
size.
Quadratic O(n2 ) Number of operations proportional to the square of
the size of the input data.
Cubic O(n3 ) Number of operations proportional to the cube of the
size of the input data.
Exponential O(2n) Exponential number of operations, fast growing.
O(kn )
O(n!)
22
Time Complexities of various
Algorithms

23

You might also like