Sparse Matrix Implementation
Sparse Matrix Implementation
On
SUBMITTED BY:
190030203 B. Sumanth
190030219 B. Sritha
Dr. M. Anusha
Associative Professor
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES
CERTIFICATE
We express the sincere gratitude to our Director Dr. A. Jagdeesh for his
administration towards our academic growth.
Regd . No Name
190030203 B. Sumanth
190030219 B. Sritha
Implement a sparse matrix in which any or most of the entries are zero.
Because allocating memory space for all entries of the matrix will be wasteful we
intend to allocate memory space only for nonzero entries.
Modules:
(a) Represent a sparse matrix as a doubly linked circular or any other data
structure which you think is useful.
(b) Write a program to perform the following operations:
(i) Read in inputs for the entries of a sparse matrix and form a suitable
data structure.
(ii) Addition of two sparse matrices.
(iii) Subtraction of two sparse matrices.
(iv) Multiplication of two sparse matrices.
(v) Print sparse matrix (in matrix form).
INDEX
S.NO TITLE PAGE NO
1 Introduction 1
4 Implementation (A) 4
5 Implementation (B) 5 - 12
6 Outputs/ScreenShots 13 - 17
7 Conclusion 18
INTRODUCTION
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.
[1]
AIM
Memory usage and CPU time are generally inversely proportional,
because the computer needs more time to perform operations on a compactified
data structure. The idea of sparse matrices mirrors exactly the need for less
memory load, therefore it is natural that sparse algorithms take more time than
dense ones.
Advantages:-
1. Cheaper to store
2. As a lot of elements are zero, it reduces the total computational time
taken for operations
Disadvantages:-
Future enhancements:-
1. Using Sparse Matrices for IR.
2. Proximity Search using Sparse Matrix Multiplication.
3. Relevance Feedback using Sparse Matrix Multiplication.
[2]
SYSTEM REQUIREMENTS
➢ SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Java
Operating system: Windows Xp or later.
Complier: Java Compiler , JVM , Eclipse Ide.
➢ HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
[3]
[A] IMPLEMENTATION
Using Arrays:-
In linked list, each node has four fields. These four fields are defined as:
[4]
[B] IMPLEMENTATION
<LIBARARY CLASS>
package matrix;
class Node
{
int value;
int row;
int col;
Node nxt;
}
<MAIN CLASSS>
package matrix;
import java.util.Scanner;
public class Project
{
Node
head1=null,head2=null,tail1=null,tail2=null,r1,r2,r,ra,temp,s,heada=null,taila
=null,tails=null,heads=null,rs,headm=null,tailm=null,rm;
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
Project obj=new Project();
int m1,m2,n1,n2,i,j,ch=0,k,sum=0;
System.out.println("ENTER YOUR FIRST MATRIX SIZE:");
m1=s.nextInt();
n1=s.nextInt();
System.out.println("ENTER YOUR SECOND MATRIX SIZE:");
m2=s.nextInt();
n2=s.nextInt();
int a[][]=new int[m1][n1];
int b[][]=new int[m2][n2];
int c[][]=new int[m1][n1];
int m[][]=new int[m1][n1];
int d[][]=new int[m1][n1];
System.out.println("ENTER YOUR FIRST MATRIX ELEMENTS:");
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++)
{
a[i][j]=s.nextInt();
if(a[i][j]!=0)
{ [5]
obj.create1(a[i][j],i,j);
}
}
}
System.out.println("ENTER YOUR SECOND MATRIX ELEMENTS:");
for(i=0;i<m2;i++)
{
for(j=0;j<n2;j++)
{
b[i][j]=s.nextInt();
if(b[i][j]!=0)
{
obj.create2(b[i][j],i,j);
}
}
}
[12]
INTEGRATION AND SYSTEM TESTING
OUTPUTS
Screen Shots:
[13]
[]
[15]
[16]
[17]
CONCLUSION
Previously, we introduced a sparse matrix approach to information
retrieval. This approach represented the inverted index as a sparse matrix. The
motivation for the approach was the reuse of prior mathematical efforts for a
novel application, namely information retrieval. However, the approach was not
evaluated until now where an evaluation of this approach demonstrated up to a
30% reduction in storage space over a conventional approach.
[18]