![]() |
A matrix with a high proportion of zero members is called a Sparse Matrix. Memory and computing resources may be conserved by effectively representing and manipulating sparse matrices. Java provides many methods for doing fundamental operations and representing sparse matrices. In this article, we will learn to sparse matrix representation and operations in Java. Implementation of a Sparse Matrix RepresentationThe key idea is to use a data structure that only keeps the non-zero items and their row and column indices to describe a sparse matrix. Typical depictions include:
Program to Sparse Matrix Representation and OperationsLet’s use an array of arrays to represent a sparse matrix and carry out some fundamental operations: Java
Output
Matrix 1: 1 0 2 0 3 0 0 0 0 Matrix 2: 4 0 5 0 6 0 0 0 0 The Resultant Matrix (Sum of Matrix 1 and Matrix 2): 5 0 7 0 9 0 0 0 0 Explanation of the above Program:
Complexity of the above Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |