Friday, 21 September 2018

Introduction to matrix and types of array

Matrix and array


Matrix

Matrix is a rectangular array of numbers arranged in rows (horizontal lines) and columns (vertical lines) enclosed between a pair of round or square brackets. E.g.


Example of matrices
EXAMPLES OF MATRIX











Order of matrix

Order or size of a matrix is given by the number of rows followed by the number of columns. In the example the first matrix has one row and two columns, so the order is 1*2 (read as 1 by 2). Similarly, the order of other matrices is 2*2, 3*3, 3*1.


Array

An array is a homogeneous (same type) collection of elements or data having a common property and sharing a common name. It can be declared normally like ordinary variables using [ ] for size specification.

For e.g. int a[5] is used to store 5 integer values in a[0],a[1],a[2],a[3],a[4].

a[0] is first element of array a. a[0],a[1],a[2],a[3],a[4] are called elements or subscripts.

All 5 variables are stored in different memory locations.



Types of array 


Single dimensional array
                                           The array having only a single pair of brackets with array name is called single dimensional array. They have single size specification.E.g. a[5].



Multidimensional array
                                         The array having more than one pair of brackets with the array name is called a multidimensional array. They have multiple size specification.
E.g. ex[5][5]g[2][4][2].

           
two-dimensional array is an array having a pair of square brackets(or having two dimensions). It is an example of multidimensional array. It has a double size specification. A two-dimensional array is used for the implementation of a matrix. When a two-dimensional array is implemented as a matrix, the first dimension represents the number of rows and the second dimension represents the number of columns. E.g. a[2][2]a[3][2]a[4][4].

An array a[2][2] will have four elements which are a[0][0]a[0][1]a[1][0]a[1][1].







No comments:

Post a Comment