Sie sind auf Seite 1von 6

Data Structures

Using C++

Ms.Akhila Shaji
Assistant Professor
SSM College,Rajakkad
Applications of arrays

 Sparse Matrix representation and operations


 Polynomial representation and operations
Sparse Matrix representation and operations

• A matrix is a two-dimensional data object made of m


rows and n columns, therefore having total m x n
values. If most of the elements of the matrix have 0
value, then it is called a sparse matrix. A matrix that is
not sparse is called dense matrix.

• Example:
00304
00570
00000
02600
• There are various situations in which sparse matrix is used
with different names. A few such situations are
1. The diagonal matrix is a matrix in which all non-zero
elements lie on the diagonal and rest of the elements are
having zero values.
Eg: 1 0 0
0 5 0
0 0 9
2. Upper triangular matrix is a matrix in which all the
elements on or above the diagonal have non-zero values and
rest of the elements have zero values.
Eg: 1 2 3
0 7 5
0 0 6
3. Lower triangular matrix is a matrix in which all the non-
zero elements occur on or below the diagonal.
Eg: 1 0 0
4 5 0
6 3 7
(Sparse matrix contd.)

• Representing a sparse matrix by a 2D array leads to


wastage of lots of memory as zeroes in the matrix are of
no use in most of the cases.
•A sparse matrix requires an alternate form of
representation. While dealing with large matrices that
are sparse, we have to think about an alternative
representation to store only the non-zero elements for
better space utilization. Each element of the matrix is
uniquely characterized by its row and column
positions. So a triple (i, j, value) can easily represent the
non-zero elements of the matrix.
In the sparse representation of a matrix, there are three
columns. In the first row, we always specify the number of
rows, columns, and non-zero elements
(No_Of_NonZeroValues) in columns 1, 2, and 3,
respectively. From the second row onwards, we store each
non-zero element by its triple (i, j, value). So in a sparse
matrix, there are three columns and
(No_Of_NonZeroValues + 1) rows.

So, instead of storing zeroes with non-zero elements, we


only store non-zero elements. This means storing non-zero
elements with triples- (Row, Column, value).
•Sparse Matrix Representations can be done in many ways
following are two common representations:
Array representation
Linked list representation

Das könnte Ihnen auch gefallen