Two Dimensional Array

  • Two dimensional arrays are also called table or matrix, two dimensional arrays have two subscripts
  • Two dimensional array in which elements are stored column by column is called as column major matrix
  • Two dimensional array in which elements are stored row by row is called as row major matrix
  • First subscript denotes number of rows and second subscript denotes the number of columns
  • Two dimensional array consisting of two rows and four columns as above Fig 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 ]
  • The address of element A [ i , j ] can be obtained by expression Loc (A [ i , j ]) = L0+ (j-1)*2 + i-1
  • 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)
  • In row major matrix, array can be generalized to arbitrary lower and upper bound in its subscripts, assume that b1 ≤ I ≤ u1 and b2 ≤ j ≤u2
  • For row major matrix : Loc (A [ i , j ]) = L0+ ( i –b1 ) *(u2-b2+1) + (j-b2)

two dimensi

For any query or issue, feel free to discuss on http://discuss.eduguru.in