Presentation is loading. Please wait.

Presentation is loading. Please wait.

Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.

Similar presentations


Presentation on theme: "Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such."— Presentation transcript:

1 Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such J, K) called subscripts with property that 1 <= J <= m 1 <= K <= n The element with first subscript j and subscript k is denoted by Aj,k or A[J,K] The elements of A form a rectangular array with m rows and n columns and the element A[J,K] appears in a row J and column K

2 A row is a horizontal list of elements A column is a vertical list of elements Representation of 2D Arrays in memory Although A is pictured as a rectangular array of elements with m rows and n columns, but the array will be represented in memory by a block of m. n sequential memory locations. Array can be stored in two ways 1.Column major order 2.Row major order

3 In column major order elements are stored column by column In row major order elements are stored row by row How To find the address of element A[J,K] in 2D m x n array A we can use following formulae For column major order: LOC(A[J,K]) = Base(A) + w ( M(K-1) + (J-1) ) For row major order: LOC(A[J,K]) = Base(A) + w ( N(J-1) + (K-1) ) w denotes the no. of words per memory location

4 Pointers & Pointer Arrays Let DATA be any array a variable ‘P’ is called pointer if P points to an element in DATA, i.e. if P contains the address of an element in DATA. An array “PTR” is called pointer array if each element of array is pointer.

5 Records & Record Structures Define record? Field? File? Elementary data items? Group data items?

6 A record is a collection of related data items, each of which is called a field or attribute and a file is collection of similar record.

7 Representation of records in memory ; Parallel Arrays Since records may contain non homogeneous data, the elements of record cannot be stored in an array; but some programming languages have record structures built into the language. But if structures are not available, and our record contains non homogeneous data, then we can store the elements in different arrays with same subscript belong to the same record…… this represents the parallel array……

8 Matrices and Vectors An n-element vector V is a list of n numbers usually given in the form V = (V1, V2, V3, ……., Vn) An m x n matrix A is an array of m. n numbers arranged in m rows an n columns Sparse Matrices : matrices with relatively high proportion of zero entries are called Sparse Matrices.

9 Triangular matrices : the matrix where all entries above the main diagonal are zero, or equivalently where non zero elements can only occur on or below the main diagonal is called a triangular matrix. Tridiagonal matrix : the matrix where non zero entries can only occur on the diagonal is called tridiagonal matrix.


Download ppt "Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such."

Similar presentations


Ads by Google