Discuss beneficial and often necessary to use specialized algorithms and data structures that take advantage of the sparse structure of the matrix.

Description:
Sparse matrices are matrices populated primarily with zeros (lecture 11). When storing and manipulating sparse matrices on a computer, it is beneficial and often necessary to use specialized algorithms and data structures that take advantage of the sparse structure of the matrix. You are required to implement the sparseMatrix data structure described as follows. Your sparseMatrix should consist of an array of chains (see figure below). Each chain holds the non-zero elements of the corresponding row in the matrix. These non-zero elements can be of type boolean or integer. All of the elements of a sparseMatrix must be of the same type, i.e. a sparseMatrix cannot contain both integers and booleans. Thus, your sparseMatrix class must be templated.

For your sparseMatrix data structure, you must implement a constructor, destructor, print, read, and mask methods. You may also implement any helper function(s) at your own discretion.
– The read function receives input from standard input (stdin) and creates a sparse matrix by assigning values to the internal structures of the matrix.
– The print function prints out the elements of the matrix, in the format shown in the example below.
– The sparseMatrix method mask(b,c), has an implicit third operand. The operand is this (the object invoking the method). The mask(b,c) method stores the result of masking this and b into the sparseMatrix c.
– Masking a matrix is defined as follows:
c(i,j) = a(i,j) if b(i,j) is true, and
c(i,j) =0 otherwise,
where b is a boolean sparse matrix, and a and b are integer sparse matrices.
– You need to explicitly instantiate two matrices with type int, and one matrix with type boolean. Your main matrix and result matrix will contain integers. Your mask matrix will contain booleans.
– You may assume that all matrices will have the same dimensions.

– Note: As you read in matrix b, you will read integer values from the input, but store boolean values into b. As you read in matrix a, you will read (and store) integer values.

Sample test:
int main()
{
sparseMatrix<int>* a = new sparseMatrix<int>();
sparseMatrix<bool>* b = new sparseMatrix<bool>();
sparseMatrix<int>* c = new sparseMatrix<int>();
cout << “Reading Matrix A” << endl;
a->read();
cout << “Matrix A:” << endl;
a->print();
cout << “Reading Matrix B” << endl;
b->read();
cout << “Matrix B, the boolean mask matrix:” << endl;
b->print();
// Masking
a->mask(*b,*c);
cout << “Matrix C, result:” << endl;
c->print();
return 0;
}

Sample input and output (user input is shown in RED):
Reading Matrix A
Enter number of rows, columns
3 4
Enter number of terms in row 1
1
Enter element’s column, and value of each term in row 1
1 111
Enter number of terms in row 2
2
Enter element’s column, and value of each term in row 2
2 222 3 233
Enter number of terms in row 3
0

Matrix A:
rows = 3 columns = 4
row 1[ col:1 val= 111]
row 2[ col:2 val= 222, col:3 val= 233]
row 3[]

Reading Matrix B
Enter number of rows, columns
3 4
Enter number of terms in row 1
1
Enter element’s column, and value of each term in row 1
1 1
Enter number of terms in row 2
1
Enter element’s column, and value of each term in row 2
3 1
Enter number of terms in row 3
0

Matrix B, the boolean mask matrix:
rows = 3 columns = 4
row 1[ col:1 val= 1]
row 2[ col:3 val= 1]
row 3[]

Matrix C, result:
rows = 3 columns = 4
row 1[ col:1 val= 111]
row 2[ col:3 val= 233]
row 3[]

Last Completed Projects

topic title academic level Writer delivered

Are you looking for a similar paper or any other quality academic essay? Then look no further. Our research paper writing service is what you require. Our team of experienced writers is on standby to deliver to you an original paper as per your specified instructions with zero plagiarism guaranteed. This is the perfect way you can prepare your own unique academic paper and score the grades you deserve.

Use the order calculator below and get started! Contact our live support team for any assistance or inquiry.

[order_calculator]