4. Introduction
A collection of a fixed number of components
✗ all of the same type
✗ structured in TWO dimensions
✗ arranged in rows and columns
✗ also knowns as table and matrix
✗ where first element has 1 index
✗ each component accessed by a PAIR of indices
representing the component’s position in each
dimension.
4
8. Sorting
There are two ways of representing
2D array in memory:
✗Row Major: elements of array store
in contiguous memory locations row
by row.
✗Column Major: elements of array
store in contiguous memory locations
column by column.
8
10. location of an element in 2D
Array(row major order)
Formula for row major:
total num of col row num of element
Array[i][j] = Base+w( n(i-1)+(j-1) )
base address word size col num of element
10
11. Numeric Example
In figure there is 3x3 array and memory location start
from 200 and each element take 2 address. Calculate
element at Array [3][1] for both row and column
major?
Ans. here m=n=3
I =3, j=1, w=2, base address=200
Formula for row major
Array[i][j] = Base+w( n(i-1)+(j-1) )
= 200+2(3(3-1)+(1-1))
= 212
11
13. Credits
Special thanks to all the people who made and
released these awesome resources for free:
✗http://www.hackviper.com/viper_article_page/502/data_structures/Calculate_
memory_Address_of_Elements_in_2D_Array
✗http://www.xpode.com/ShowArticle.aspx?ArticleId=500
✗http://thecodegallery.com/DSM/RowMajor.php
✗https://www.slideshare.net/shangondal/2d-array-70589183/7
13