Matrix 1
Matrix 1
The 2-dimensional array can be defined as an array of arrays. The 2-Dimensional arrays are
organized as matrices which can be represented as the collection of rows and columns as
array[M][N] where M is the number of rows and N is the number of columns.
To find the address of any element in a 2-Dimensional array there are the following two ways-
1.Row Major Order
2.Column Major Order
= 1046 + 2[21 + 2]
= 1046 + 46
= 1092.
What is Sparse Matrix?
In computer programming, a matrix can be defined with a 2-dimensional array. Any array with 'm'
columns and 'n' rows represent a m X n matrix. There may be a situation in which a matrix
contains more number of ZERO values than NON-ZERO values. Such matrix is known as sparse
matrix.
When a sparse matrix is represented with a 2-dimensional array, we waste a lot of space to
represent that matrix. For example, consider a matrix of size 100 X 100 containing only 10 non-
zero elements. In this matrix, only 10 spaces are filled with non-zero values and remaining spaces
of the matrix are filled with zero. That means, totally we allocate 100 X 100 X 2 = 20000 bytes of
space to store this integer matrix. And to access these 10 non-zero elements we have to make
scanning for 10000 times. To make it simple we use the following sparse matrix representation.
Sparse Matrix Representations
A sparse matrix can be represented by using TWO representations, those are as follows...
Triplet Representation (Array Representation)
In this representation, we consider only non-zero values along with their row and column index
values. In this representation, the 0th row stores the total number of rows, total number of
columns and the total number of non-zero values in the sparse matrix.
For example, consider a matrix of size 5 X 6 containing 6 number of non-zero values. This
matrix can be represented as shown in the image...
What is Linear Search Algorithm?
Linear search is a method for searching for an element in a collection of elements. In linear
search, each element of the collection is visited one by one in a sequential fashion to find the
desired element. Linear search is also known as sequential search.
else
high = mid - 1;
}
return -1;
}
Types of Asymptotic Notations in Complexity Analysis of Algorithms