0% found this document useful (0 votes)
15 views8 pages

1.2.4 Multidimensional Array

Uploaded by

muhehemuhehe7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

1.2.4 Multidimensional Array

Uploaded by

muhehemuhehe7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Department of Computer Science and Engineering (CSE)

Multidimensional arrays

Two – dimensional Arrays

• Array having more than one subscript variable is called Multi-Dimensional array.
• A Two – dimensional Arrays m x n array A is a collection of m . n data elements such
that each element is specified by a pair of integers (such as I, J), called subscripts.
• The element of A with first subscript I and second subscript J will be denoted by
A[I,J]
Columns

1 2 3
1 A[1, 1] A[1, 2] A[1, 3]
Rows 2
A[2, 1] A[2, 2] A[2, 3]
3
A[3, 1] A[3, 2] A[3, 3]

Fig: Two dimensional 3 x 3 array A

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Declaration and Use of Two Dimensional Array

• Declaration : Meaning of Two Dimensional Array :


int a[3][4]; 1. Matrix is having 3 rows ( i takes value from 0
to 2 )
• Use : 2. Matrix is having 4 Columns ( j takes
for(i=0;i<3;i++) value from 0 to 3 )
3. Above Matrix 3×4 matrix will have 12 blocks
{ having 3 rows & 4 columns.
for(j=0;j<4;j++) 4. Name of 2-D array is ’a’ and each block is
identified by the row & column number.
{ 5. Row number and column number starts
cout<<a[i][j]<<“ “; from 0.
}
cout<<“\n”;
}
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)

Memory Representation of 2-D array


• 2-D arrays are Stored in contiguous memory location row
wise.
• Consider 3×3 Array is stored in contiguous memory
location which starts from some base address(e.g.4000) .
• Array element a[1][1] will be stored at address 4000,
again a[1][2]will be stored to next memory location i.e
elements stored row-wise.
• After Elements of First Row are stored in appropriate
memory location, then second row and so on.
• If we are taking integer array , then each element will
require 2 bytes of memory.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Array Representation of 2-D array


• Column-major
• Row-major
 Arrays may be represented in Row-major form or
Column-major form.
 In Row-major form, all the elements of the first row are
printed, then the elements of the second row and so on
up to the last row.
 In Column-major form, all the elements of the first
column are printed, then the elements of the second
column and so on up to the last column.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)
Array Representation(contd..)
Index Memory Location Element
a[1][1] 4000 1
ARRAY a[1][2] 4002 2
a[1][3] 4004 3
1 2 3 ROW-MAJOR a[2][1] 4006 4
a[2][2] 4008 5
1 a[2][3] 4010 6
a[3][1] 4012 7
2
a[3][2] 4014 8
3 a[3][3] 4016 9

Index Memory Location Element


a[1][1] 4000 1
a[2][1] 4002 4
a[3][1] 4004 7
COLUMN-MAJOR a[1][2] 4006 2
a[2][2] 4008 5
a[3][2] 4010 8
A[1][3] 4012 3
a[2][3] 4014 6
a[3][3] 4016 9

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

References
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline
Series, Tata McGraw Hill.
• Goodrich, Michael T., Tamassia, Roberto, and Mount,
David M., “Data Structures and Algorithms in C++”, Wiley
Student Edition.
• https://www.geeksforgeeks.org/array-data-structure/
• https://www.tutorialspoint.com/
data_structures_algorithms/array_data_structure.htm
• https://www.w3schools.in/data-structures-tutorial/
data-structures-arrays/

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Books Recommended
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline
Series, Tata McGraw Hill.
• Gilberg/Forouzan,” Data Structure with C ,Cengage
Learning.
• Goodrich, Michael T., Tamassia, Roberto, and Mount,
David M., “Data Structures and Algorithms in C++”, Wiley
Student Edition.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

THANKS

University Institute of Engineering (UIE)

You might also like