SlideShare a Scribd company logo
Darshan Institute of Engineering & Technology, Rajkot
Unit-2
Linear Data Structure
Array
pradyuman.jadeja@darshan.ac.in
+91 9879461848
Computer Engineering Department
Data Structures (DS)
GTU # 3130702
 Looping
Outline
 Array
• Representation of arrays
• One dimensional array
• Two dimensional array
 Applications of arrays
• Symbol Manipulation (matrix representation of polynomial equation)
• Sparse matrix
 Sparse matrix and its representation
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 3
One Dimensional Array
 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.
 A vector size is fixed and therefore requires a fixed number of memory locations.
 Vector A with subscript lower bound of “one” is represented as below….
• L0 is the address of the first word allocated to the first element of vector A
• C words is size of each element or node
• The address of element Ai is
Loc(Ai) = L0 + (C*(i-1))
• Let’s consider the more general case of a vector A with lower bound for it’s
subscript is given by some variable b.
• The address of element Ai is
Loc(Ai) = L0 + (C*(i-b))
A[i]
L0
L0+(i-1)C
i-1
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 4
Two Dimensional Array
 Two dimensional arrays are also called table or matrix
 Two dimensional arrays have two subscripts
 Column major order matrix: Two dimensional array in which elements are stored column by
column is called as column major matrix
 Two dimensional array consisting of two rows and four columns is stored sequentially by
columns : A[1,1], A[2,1], A[1,2], A[2,2], A[1,3], A[2,3], A[1,4], A[2,4]
[1,1] [1,2] [1,3] [1,4]
[2,1] [2,2] [2,3] [2,4]
Row 1
Row 2
Col-1 Col-2 Col-3 Col-4
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 5
Column major order matrix
 The address of element A [ i , j ] can be obtained by expression
Loc (A [ i , j ]) = L0 + (j-1)*2 + (i-1)
Loc (A [2, 3]) = L0 + (3-1)*2 + (2-1) = L0 + 5
 In general for two dimensional array consisting of n rows and m columns the address element A [
i , j ] is given by
Loc (A [ i , j ]) = L0 + (j-1)*n + (i – 1)
[1,1] [1,2] [1,3] [1,4]
[2,1] [2,2] [2,3] [2,4]
Row 1
Row 2
Col-1 Col-2 Col-3 Col-4
[1,1]
[2,1]
[1,2]
[2,2]
[1,3]
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 6
Row major order matrix
 Row major order matrix: Two dimensional array in which elements are stored row by row is called
as row major matrix
• The address element A [ i , j ] is given by
Loc (A [ i , j ]) = L0 + (i-1)*m + (j – 1)
n = no of rows, m = no of columns
b1 = lower bound subscript of row
u1 = upper bound subscript of row
n = u1 – b1 + 1
b2 = lower bound subscript of column
u2 = upper bound subscript of column
m = u2 – b2 + 1
• The address element A [ i , j ] is given by
[1,1] [1,2] [1,3] [1,m]
[2,1] [2,2] [2,3] [2,m]
[n,1] [n,2] [n,3] [n,m]
nxm
b1
u1
b2 u2
Loc (A [ i , j ]) = L0 + (i-b1)*(u2-b2+1) + (j – b2)
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 7
Applications of Array
1. Symbol Manipulation (matrix representation of polynomial equation)
2. Sparse Matrix
 Matrix representation of polynomial equation
 We can use array for different kind of operations in polynomial equation such as addition, subtraction, division,
differentiation etc…
 We are interested in finding suitable representation for polynomial so that different operations like addition,
subtraction etc… can be performed in efficient manner.
 Array can be used to represent Polynomial equation.
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 8
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
X
X2
X3
X4
Y Y2 Y3 Y4
Representation of Polynomial equation
2X2 + 5XY + Y2
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
X
X2
X3
X4
Y Y2 Y3 Y4
2
5
1
X2 + 3XY + Y2+Y-X
1
3
1
1
-1
Y Y2 Y3 Y4
X XY XY2 XY3 XY4
X2 X3Y X2Y2 X2Y3 X2Y4
X3 X3Y X3Y2 X3Y3 X3Y4
X4 X4Y X4Y2 X4Y3 X4Y4
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 9
Sparse matrix
 An m x n matrix is said to be sparse if “many” of its elements are zero.
 A matrix that is not sparse is called a dense matrix.
 We can device a simple representation scheme whose space requirement equals the size of the
non-zero elements.
0 0 0 2 0 0 1 0
0 6 0 0 7 0 0 3
0 0 0 9 0 8 0 0
0 4 5 0 0 0 0 0
Terms
Row
Column
Value
4x8
Row - 1
Row - 2
Row - 3
Row - 4
Column
-
1
Column
-
2
Column
-
3
Column
-
4
Column
-
5
Column
-
6
Column
-
7
Column
-
8
Linear Representation of given matrix
0
1
4
2
1
1
7
1
2
2
2
6
3
2
5
7
4
2
8
3
5
3
4
9
6
3
6
8
7
4
2
4
8
4
3
5
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 10
Sparse matrix Cont…
 To construct matrix structure from liner representation we need to record.
 Original row and columns of each non zero entries.
 Number of rows and columns in the matrix.
 So each element of the array into which the sparse matrix is mapped need to have three fields:
row, column and value
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 11
Sparse matrix Cont…
0 0 6 0 9 0 0
2 0 0 7 8 0 4
10 0 0 0 0 0 0
0 0 12 0 0 0 0
0 0 0 0 0 0 0
0 0 0 3 0 0 5
Row Column A
6x7
1
2
3
4
5
6
1 2 3 4 5 6 7
Memory Space required to store
6x7 matrix
42 x 2 = 84 bytes
Memory Space required to store
Linear Representation
30 x 2 = 60 bytes
Linear representation of Matrix
A =
1 3 6
1 5 9
2 1 2
2 4 7
2 5 8
2 7 4
3 1 10
4 3 12
6 4 3
6 7 5
Space Saved = 84 – 60 = 24 bytes
Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 12
Sparse matrix Cont…
Row
1
1
2
2
2
2
3
4
6
6
Column
3
5
1
4
5
7
1
3
4
7
A
6
9
2
7
8
4
10
12
3
5
Linear Representation of Matrix
Column
3
5
1
4
5
7
1
3
4
7
A
6
9
2
7
8
4
10
12
3
5
Linear Representation of Matrix
Row
1
3
7
8
0
9
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
Memory Space required to store Liner Representation = 26 x 2 = 42 bytes
Darshan Institute of Engineering & Technology, Rajkot
Thank
You
pradyuman.jadeja@darshan.ac.in
+91 9879461848
Computer Engineering Department
Data Structures (DS)
GTU # 3130702

More Related Content

PPTX
Data strutcure and annalysis topic array
PPTX
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
PPTX
data structure and algorithm Array.pptx btech 2nd year
PPTX
Basic of array and data structure, data structure basics, array, address calc...
PDF
2D Array
PPTX
Addressing Formulas for Sparse Matrices Using Column Major in 1D Arrays.pptx
PPTX
arrays in data structure.pptx
PPTX
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Data strutcure and annalysis topic array
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
data structure and algorithm Array.pptx btech 2nd year
Basic of array and data structure, data structure basics, array, address calc...
2D Array
Addressing Formulas for Sparse Matrices Using Column Major in 1D Arrays.pptx
arrays in data structure.pptx
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE

Similar to array.pptx (20)

PPTX
arrays.pptx
PPT
Relations & functions
PPT
1st lecture.ppt
PDF
cluod.pdf
PPT
Chapter 3 ds
PPTX
Introduction to data structures using c/c++.pptx
PDF
relationsandfunctionslessonproper-160929053921.pdf
PPT
Structured Data Type Arrays
PPT
1st lecture of DSA computer science 2024.ppt
PDF
relationsandfunctionslessonproper-160929053921.pdf
PDF
FUZZY ARITHMETIC OPERATIONS ON DIFFERENT FUZZY NUMBERS AND THEIR VARIOUS FUZZ...
PPTX
PPTX
PPT
Relations and functions
PPT
Arrays
PPTX
MATLAB - Arrays and Matrices
PDF
DATA STRUCTURE BY SIVASANKARI
PPTX
Two Dimentional Array
PPTX
Sparse matrix and its representation data structure
PPTX
How to handling strings in r
arrays.pptx
Relations & functions
1st lecture.ppt
cluod.pdf
Chapter 3 ds
Introduction to data structures using c/c++.pptx
relationsandfunctionslessonproper-160929053921.pdf
Structured Data Type Arrays
1st lecture of DSA computer science 2024.ppt
relationsandfunctionslessonproper-160929053921.pdf
FUZZY ARITHMETIC OPERATIONS ON DIFFERENT FUZZY NUMBERS AND THEIR VARIOUS FUZZ...
Relations and functions
Arrays
MATLAB - Arrays and Matrices
DATA STRUCTURE BY SIVASANKARI
Two Dimentional Array
Sparse matrix and its representation data structure
How to handling strings in r
Ad

Recently uploaded (20)

PPTX
UNIT 4 Total Quality Management .pptx
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT
Occupational Health and Safety Management System
PPT
Total quality management ppt for engineering students
PPTX
Artificial Intelligence
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
introduction to datamining and warehousing
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
737-MAX_SRG.pdf student reference guides
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
UNIT 4 Total Quality Management .pptx
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
III.4.1.2_The_Space_Environment.p pdffdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Automation-in-Manufacturing-Chapter-Introduction.pdf
Occupational Health and Safety Management System
Total quality management ppt for engineering students
Artificial Intelligence
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
introduction to datamining and warehousing
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Fundamentals of Mechanical Engineering.pptx
Abrasive, erosive and cavitation wear.pdf
737-MAX_SRG.pdf student reference guides
Soil Improvement Techniques Note - Rabbi
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Ad

array.pptx

  • 1. Darshan Institute of Engineering & Technology, Rajkot Unit-2 Linear Data Structure Array pradyuman.jadeja@darshan.ac.in +91 9879461848 Computer Engineering Department Data Structures (DS) GTU # 3130702
  • 2.  Looping Outline  Array • Representation of arrays • One dimensional array • Two dimensional array  Applications of arrays • Symbol Manipulation (matrix representation of polynomial equation) • Sparse matrix  Sparse matrix and its representation
  • 3. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 3 One Dimensional Array  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.  A vector size is fixed and therefore requires a fixed number of memory locations.  Vector A with subscript lower bound of “one” is represented as below…. • L0 is the address of the first word allocated to the first element of vector A • C words is size of each element or node • The address of element Ai is Loc(Ai) = L0 + (C*(i-1)) • Let’s consider the more general case of a vector A with lower bound for it’s subscript is given by some variable b. • The address of element Ai is Loc(Ai) = L0 + (C*(i-b)) A[i] L0 L0+(i-1)C i-1
  • 4. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 4 Two Dimensional Array  Two dimensional arrays are also called table or matrix  Two dimensional arrays have two subscripts  Column major order matrix: Two dimensional array in which elements are stored column by column is called as column major matrix  Two dimensional array consisting of two rows and four columns is stored sequentially by columns : A[1,1], A[2,1], A[1,2], A[2,2], A[1,3], A[2,3], A[1,4], A[2,4] [1,1] [1,2] [1,3] [1,4] [2,1] [2,2] [2,3] [2,4] Row 1 Row 2 Col-1 Col-2 Col-3 Col-4
  • 5. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 5 Column major order matrix  The address of element A [ i , j ] can be obtained by expression Loc (A [ i , j ]) = L0 + (j-1)*2 + (i-1) Loc (A [2, 3]) = L0 + (3-1)*2 + (2-1) = L0 + 5  In general for two dimensional array consisting of n rows and m columns the address element A [ i , j ] is given by Loc (A [ i , j ]) = L0 + (j-1)*n + (i – 1) [1,1] [1,2] [1,3] [1,4] [2,1] [2,2] [2,3] [2,4] Row 1 Row 2 Col-1 Col-2 Col-3 Col-4 [1,1] [2,1] [1,2] [2,2] [1,3]
  • 6. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 6 Row major order matrix  Row major order matrix: Two dimensional array in which elements are stored row by row is called as row major matrix • The address element A [ i , j ] is given by Loc (A [ i , j ]) = L0 + (i-1)*m + (j – 1) n = no of rows, m = no of columns b1 = lower bound subscript of row u1 = upper bound subscript of row n = u1 – b1 + 1 b2 = lower bound subscript of column u2 = upper bound subscript of column m = u2 – b2 + 1 • The address element A [ i , j ] is given by [1,1] [1,2] [1,3] [1,m] [2,1] [2,2] [2,3] [2,m] [n,1] [n,2] [n,3] [n,m] nxm b1 u1 b2 u2 Loc (A [ i , j ]) = L0 + (i-b1)*(u2-b2+1) + (j – b2)
  • 7. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 7 Applications of Array 1. Symbol Manipulation (matrix representation of polynomial equation) 2. Sparse Matrix  Matrix representation of polynomial equation  We can use array for different kind of operations in polynomial equation such as addition, subtraction, division, differentiation etc…  We are interested in finding suitable representation for polynomial so that different operations like addition, subtraction etc… can be performed in efficient manner.  Array can be used to represent Polynomial equation.
  • 8. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X X2 X3 X4 Y Y2 Y3 Y4 Representation of Polynomial equation 2X2 + 5XY + Y2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X X2 X3 X4 Y Y2 Y3 Y4 2 5 1 X2 + 3XY + Y2+Y-X 1 3 1 1 -1 Y Y2 Y3 Y4 X XY XY2 XY3 XY4 X2 X3Y X2Y2 X2Y3 X2Y4 X3 X3Y X3Y2 X3Y3 X3Y4 X4 X4Y X4Y2 X4Y3 X4Y4
  • 9. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 9 Sparse matrix  An m x n matrix is said to be sparse if “many” of its elements are zero.  A matrix that is not sparse is called a dense matrix.  We can device a simple representation scheme whose space requirement equals the size of the non-zero elements. 0 0 0 2 0 0 1 0 0 6 0 0 7 0 0 3 0 0 0 9 0 8 0 0 0 4 5 0 0 0 0 0 Terms Row Column Value 4x8 Row - 1 Row - 2 Row - 3 Row - 4 Column - 1 Column - 2 Column - 3 Column - 4 Column - 5 Column - 6 Column - 7 Column - 8 Linear Representation of given matrix 0 1 4 2 1 1 7 1 2 2 2 6 3 2 5 7 4 2 8 3 5 3 4 9 6 3 6 8 7 4 2 4 8 4 3 5
  • 10. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 10 Sparse matrix Cont…  To construct matrix structure from liner representation we need to record.  Original row and columns of each non zero entries.  Number of rows and columns in the matrix.  So each element of the array into which the sparse matrix is mapped need to have three fields: row, column and value
  • 11. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 11 Sparse matrix Cont… 0 0 6 0 9 0 0 2 0 0 7 8 0 4 10 0 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 5 Row Column A 6x7 1 2 3 4 5 6 1 2 3 4 5 6 7 Memory Space required to store 6x7 matrix 42 x 2 = 84 bytes Memory Space required to store Linear Representation 30 x 2 = 60 bytes Linear representation of Matrix A = 1 3 6 1 5 9 2 1 2 2 4 7 2 5 8 2 7 4 3 1 10 4 3 12 6 4 3 6 7 5 Space Saved = 84 – 60 = 24 bytes
  • 12. Dr. Pradyumansinh U. Jadeja #3130702 (DS)  Unit 2 – Linear Data Structure (Array) 12 Sparse matrix Cont… Row 1 1 2 2 2 2 3 4 6 6 Column 3 5 1 4 5 7 1 3 4 7 A 6 9 2 7 8 4 10 12 3 5 Linear Representation of Matrix Column 3 5 1 4 5 7 1 3 4 7 A 6 9 2 7 8 4 10 12 3 5 Linear Representation of Matrix Row 1 3 7 8 0 9 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 Memory Space required to store Liner Representation = 26 x 2 = 42 bytes
  • 13. Darshan Institute of Engineering & Technology, Rajkot Thank You pradyuman.jadeja@darshan.ac.in +91 9879461848 Computer Engineering Department Data Structures (DS) GTU # 3130702