Algorithms and Abstract Data Types

In this assignment you will create a calculator for performing matrix operations that exploits the (expected)
sparseness of it’s matrix operands. An × square matrix is said to be sparse if the number of non-zero
entries (abbreviated NNZ) is small compared to the total number of entries,
2
. The result will be a Java
program capable of performing fast matrix operations, even on very large matrices, provided they are
sparse.
Given × matrices A and B, their product = ⋅ is the × matrix whose th
entry is given by
= ∑
=1 .
Thus the element in the i
th row and j
th column of C is the vector dot product of the i
th row of A with the j
th
column of B. If we consider addition and multiplication of real numbers to be our basic operations, then
the above formula can be computed in time Θ(
3
), which is impractical for matrix sizes n of more than a
few thousand. If it so happens that A and B are sparse, then a great many of these arithmetic operations
involve adding or multiplying by zero, hence are unnecessary.
The sum S, and difference D, of A and B are the × matrices having th
entries:
= + and = −
The scalar product of a real number x with A is denoted , and has th
entry ( ) = ⋅ . The
transpose of A, denoted
, is the matrix whose

entry is the

entry of A: (
) = . In other
words, the rows of A are the columns of
, and the columns of A are the rows of
. Each of these
operations can be computed in time Θ(
2
), and just as for multiplication, their cost can be improved upon
significantly when A and B are sparse.
As one would expect, the cost of a matrix operation depends heavily on the choice of data structure used
to represent the matrix operands. There are several ways to represent a square matrix with real entries. The
standard approach is to use a 2-dimensional × array of doubles. The advantage of this representation
is that all of the above matrix operations have a straight-forward implementation using nested loops. This
project will use a very different representation however. Here you will represent a matrix as a 1-dimensional
array of Lists. Each List will represent one row of the Matrix, but only the non-zero entries will be stored.
Therefore List elements must store, not just the matrix entries, but the column index in which those entries
reside. For example, the matrix below would have the following representation as an array of Lists.
= [
1.0 0.0 2.0
3.0 0.0 0.0
0.0 4.0 5.0
] Array of Lists: [
1: (1,1.0) (3,2.0)
2: (1,3.0)
3: (2,4.0) (3,5.0)
This method obviously results in a substantial space savings when the Matrix is sparse. In addition, the
standard matrix operations defined above can be performed more efficiently on sparse matrices. As you
will see though, the matrix operations are much more difficult to implement using this representation. The
trade-off then, is a gain in space and time efficiency for sparse matrices, at the expense of more complicated
algorithms for performing standard matrix operations. Designing these algorithms in terms of our List ADT
operations will constitute the majority of the work you do on this assignment.
It will be necessary to make some minor changes to your List ADT from pa1. First you must convert your
List ADT from a List of ints to a List of Objects. This entails changing certain field types, declaration
statements, method parameters, and return types from int to Object. The Objects referred to by these List
elements will be defined in the Matrix ADT specified below. Second, it will be necessary to eliminate the
List operations copy() and cat() (which was optional anyway.) All other List operations from pa1 will be
retained. The equals() operation however will be altered slightly so as to override, rather than overload
Object’s built in equals() method. This is done by changing it’s signature from boolean equals(List
L), as in pa1 to public boolean equals(Object x), which is it’s signature in the superclass Object.
Indeed, all equals() methods in this project should carry this same signature.
File Formats
The top level client module for this project will be called Sparse.java. It will take two command line
arguments giving the names of the input and output files, respectively. The input file will begin with a
single line containing three integers n, a and b, separated by spaces. The second line will be blank, and the
following a lines will specify the non-zero entries of an × matrix A. Each of these lines will contain a
space separated list of three numbers: two integers and a double, giving the row, column, and value of the
corresponding matrix entry. After another blank line, will follow b lines specifying the non-zero entries of
an × matrix B. For example, the two matrices
 

What Students Are Saying About Us

.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐
"Honestly, I was afraid to send my paper to you, but splendidwritings.com proved they are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"

.......... Customer ID: 14***| Rating: ⭐⭐⭐⭐⭐
"The company has some nice prices and good content. I ordered a term paper here and got a very good one. I'll keep ordering from this website."

"Order a Custom Paper on Similar Assignment! No Plagiarism! Enjoy 20% Discount"