Loading, please wait...

Two Dimensional Array

A two-dimensional array is a collection of elements placed in m rows and n columns. There are two subscripts in the syntax of 2-D array in which one specifies the number of rows and the other number of columns. In a two- dimensional array each element is itself an array.

 

A two dimensional array is also known as matrix. Mathematically, a matrix is a collection of elements ‘aij’ for all i and j’s such that

0≤ i<m and 0<j≤n.

A matrix is said to be of order m × n. A matrix can be conveniently represented by a two-dimensional array. The various operations that can be performed on a matrix are: addition, multiplication, transposition, and finding the determinant of the matrix.

 

An example of 2D array can be myarray[2][3] containing 2 rows and 3 columns and myarray[0][1] is an element placed at 0th row and 1th column in the array.

 

A 2D array can be represented as the following figure

 

 

 



A 2D array differentiates between the logical and physical view of data. A 2D array is a logical data structure i.e. useful in programming and problem solving. For e.g. such an array is useful in describing an object i.e. physically 2D such as chessboard.



Row Major and Column Major Order

All elements of a matrix get stored in the memory in a linear fashion. The two ways in which elements can be represented in memory are:

  • Row Major order
  • Column Major order