Special Matrix

 1. Diagonal Matrix : 

For this matrix M[row, column] = 0 for all row != column

We can store non zero elements in one dimensional array to avoid storing zeros 



2. Lower Triangular Matrix : 

M[row, column] = 0 for all row < column

M[row, column] = non-zero for all row >= column

Non zero element count = 1 + 2 + 3 + ..... n = n(n+1)/2
Zero element count = n^2 - n(n+1)/2 = n(n-1)/2

Row Major Formula

Column Major Formula



3. Upper Triangular Matrix

M[row, column] = 0 for all row > column

M[row, column] = non-zero for all row <= column

Non zero element count = 1 + 2 + 3 + ..... n = n(n+1)/2
Zero element count = n^2 - n(n+1)/2 = n(n-1)/2

4. Symmetric Matrix


M[row, column] is Symmetric matrix if M[row, column] = M[column, row]

To represent it we can either use Lower Triangular Matrix or Upper Triangular Matrix.

5. Tridiagonal Matrix


Total number of elements = n + n-1 + n-1 = 3n - 2

Calculate index when represented in 1 D array 


6. Band Matrix More info

In mathematics, particularly matrix theory, a band matrix or banded matrix is a sparse matrix whose non-zero entries are confined to a diagonal band, comprising the main diagonal and zero or more diagonals on either side.


7. Toeplitz Matrix

All diagonals have same unique same value.


Represent in 1-D array



8. Sparse Matrix Most elements are zero(0).

How to represent

1. Coordinate List / 3 column representation



2. Compressed sparse row


Adding to sparse matrixes






Comments

Popular posts from this blog

SQL basic interview question

gsutil Vs Storage Transfer Service Vs Transfer Appliance