DS Unit 1
DS Unit 1
STRUCTURE
(1120501)
2
OUTLINE
> Data Management concepts
> Data types
Primitive
Non-primitive
> Types of Data Structures
Linear Data Structures
Non Linear Data Structures
> Operations on Data Structure
Introduction to Data
Structure
> What is Data?
• Data is the basic fact or entity that is utilized in calculation or
manipulation.(Real World Example: Tea Making)
• There are two different types of data Numeric(1,2,3..) data
and Alphanumeric(Aa,Bb,Cc..) data.
• When a programmer collects such type of data for processing,
he would require to store them in computer’s main
memory.
• The process of storing data items in computer’s main memory
is called representation.
• Data to be processed must be organized in a particular
fashion, these organization leads to structuring of data, and
hence the mission to study the Data Structures.
• Computer is an electronic machine which is used for data
processing and manipulation.(Real World example: Chrome:
Enter data(Search)-Processing-Manipulation(Result)) Basic
theory of Input and Output.
• In order to make computer work we need to know
o Representation of data in computer.
o Accessing of data.
o How to solve problem step by step.
For doing this task we use data structure.
> What is Data Structure?
• Data Structure is a representation of the logical relationship existing between
individual elements of data.(Ex: a represent 10, b represent 5/ Logic a+b=?)
• In other words, a data structure is a way of organizing all data items that
considers not only the elements stored but also their relationship to each
other.
• We can also define data structure as a mathematical or logical model of a
particular organization of data items.(Ex: 2x+3xy)
• The representation of particular data structure in the main memory of a
computer is called as storage structure.
• The storage structure representation in auxiliary memory is called as file
structure.
• It is defined as the way of storing and manipulating data in organized form so
that it can be used efficiently.(Ex: /,*,+,-)
• Algorithm + Data Structure = Program
• Data structure study covers the following points
o Amount of memory require to store.
o Amount of time require to process.
o Representation of data in memory.
o Operations performed on that data.
• Data Structure mainly specifies the following four things
Organization of Data
Accessing Methods
Degree of Associativity
Processing alternatives for information
5
• A data structure is said to be Linear, if its elements are connected in linear fashion by
means of logically or in sequence memory locations.
• There are two ways to represent a linear data structure in memory,
o Static memory allocation Class Task 2 : What is static and dynamic memory allocation
o Dynamic memory allocation
• The possible operations on the linear data structure are: Traversal, Insertion,
Deletion, Searching, Sorting and Merging.
• Examples of Linear Data Structure are Stack and Queue.
1) Stack: Stack is a data structure in which insertion and deletion operations are performed at one end only.
o The insertion operation is referred to as ‘PUSH’ and deletion operation
is referred to as ‘POP’ operation.
o Stack is also called as Last in First out (LIFO) data structure.
2) Queue: The data structure which permits the insertion at one end and Deletion at another end,
known as Queue.
o End at which deletion is occurs is known as FRONT end and another end
at which insertion occurs is known as REAR end.
o Queue is also called as First in First out (FIFO) data structure.
1) Nonlinear data structures :
• Nonlinear data structures are those data structure in which data items are not arranged in
a sequence.
• Examples of Non-linear Data Structure are Tree and Graph.
1) Tree: A tree can be defined as finite set of data items (nodes) in which data items are arranged in branches
and sub branches according to requirement.
o Trees represent the hierarchical relationship between various elements.
o Tree consist of nodes connected by edge, the node represented by circle and edge lives connecting to circle.
1) Graph: Graph is a collection of nodes (Information) and connecting edges (Logical relation) between nodes.
o A tree can be viewed as restricted graph.
o Graphs have many types:
o Un-directed Graph
o Directed Graph
o Mixed Graph
o Multi Graph
o Simple Graph
o Null Graph
o Weighted Graph
All elements locations is sequentially allocated to the vector. a vector size is fixed and therefore
requires a fixed number of memory locations.
A[2]row[3]column = {(1,2,3) , (4,5,6)}
}
j Junction Point : A[i][j]
0 1 2 i - row index : A[0][1]
i 0 j - column index :2
A= m - number of row
1 n – number of column Then 2 is junction point
2*3 BA – base address
m*n
BA – 50
Size – 4
1) Row Major Order(RMO): Compiler only consider row. It means data/elements compile/run in row order
2) Column Major Order(CMO): Compiler only consider column. It means data/elements compile/run in column order
00 10 01 11 02 12
Formula – [(j*m)+i] * size + base
CMO = 1 4 2 5 3 6
[(0*2)+1] * 4 + 50
50 54 58 62 66 70
[1] * 4 + 50
4 + 50
54 Store num 4 in column array
RMO CMO
Nested Loop
Output Elements
Completion of the
Main function
Output :
Output :
> One dimensional and Two-dimensional array
1) ODA : Simplest data structure that makes use of computed address to locate its elements is the one-
dimensional array or vector. Number of memory locations is sequentially allocated to the vector.
2) TDA: Two dimensional arrays are also called table or matrix
c1 c2 c3 c4 c5 c6 c7 c8
r1
r2
r3
r4
• Here from 6X7=42 elements, only 10 are non zero. A[1,3]=6, A[1,5]=9, A[2,1]=2, A[2,4]=7, A[2,5]=8,
A[2,7]=4, A[3,1]=10, A[4,3]=12, A[6,4]=3, A[6,7]=5.
• One basic method for storing such a sparse matrix is to store non-zero elements in one dimensional
array and to identify each array elements with row and column indices
> How to find array’s length
1 2 3 4 5
Index 0 1 2 3 4
Formula : UB - LB + 1
4-0+1
5
Array’s Length : 5
Note : In array all data/elements are similar for example if you want to display int data then all stored data
are integer and if you want to display char data then all data in array is char types of data
THANK
YOU
Prof. Pandya Khushi