Sparse Matrix Transpose – Programming Assignment 1 | CSC 3102, Assignments of Computer Science

Material Type: Assignment; Professor: Karki; Class: ADV DATA STRUCTURES; Subject: Computer Science; University: Louisiana State University; Term: Fall 2009;

Typology: Assignments

Pre 2010

Uploaded on 12/04/2009

buju21
buju21 🇺🇸

13 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSC 3102 Programming Assignment 1: Sparse Matrix Transpose
Due: October 6, Tuesday (by 11:55 pm)
Points: 5
Penalty: You will lose one point per delayed day
Submit your work as instructed towards the end of this document.
Contact the teaching assistant Di Lin by e-mail to [email protected] for help.
Objective:
To empirically demonstrate the difference in the performance between the naive (brute-force)
and fast-transpose algorithms on sparse matrices.
Definition:
A matrix is a concise and useful way of uniquely representing and working with linear
transformations. In particular, for every linear transformation, there exists exactly one
corresponding matrix, and every matrix corresponds to a unique linear transformation.
Matrices have wide-ranging applications in such areas as image processing, information
retrieval, computer graphics, scientific visualization, dynamical systems, etc. In this
assignment, you are dealing with the sparse matrix of order n, which has only a small number
(t) of non-zero elements. In the class, we have learned how a sparse matrix is represented as
a set of order triplets and also learned about two algorithms for obtaining its transpose (see
the lecture notes). The time-efficiency of the brute-force transpose algorithm is O(nt)
whereas that of the fast-transpose algorithm is O(n + t).
Project Task:
You will implement a sparse matrix ADT containing various functions to do the following
tasks. You can use C/C++ or JAVA programming language.
Read each input matrix Mnxn.mat. The values of n and t are given in the first line of the
input matrix M.
Find the transpose of the matrix M using the naïve (brute-forces) algorithm.
Find the transpose of the matrix M using the fast-transpose algorithm.
Print the original matrix (M) and its transpose matrix (M') in the cases of small input sizes.
Compute the time taken to find the transpose (M') using each algorithm in all input cases
using one of the two ways (see the section 2.6 of the textbook for more information).
One way is to count the number of times the basic operation is executed by putting a counter
within the innermost loop. The other way is to measure the actual execution time by using the
clock function. However, since the algorithms run very fast for the input sizes given, you
need to write and insert some delay function within the innermost loop. The delay function
can be a simple loop doing nothing. Note that in the case of the fast-transpose algorithm, you
might need to insert the counter or delay function in more than one part of the algorithm.
Once you have all these functions ready, you will read a 5 by 5 matrix from a file called
M5x5.mat, find the transpose of this matrix using the brute-force and fast-transpose
pf3

Partial preview of the text

Download Sparse Matrix Transpose – Programming Assignment 1 | CSC 3102 and more Assignments Computer Science in PDF only on Docsity!

CSC 3102 Programming Assignment 1: Sparse Matrix Transpose

Due: October 6, Tuesday (by 11:55 pm) Points: 5 Penalty: You will lose one point per delayed day Submit your work as instructed towards the end of this document. Contact the teaching assistant Di Lin by e-mail to [email protected] for help. Objective: To empirically demonstrate the difference in the performance between the naive (brute-force) and fast-transpose algorithms on sparse matrices. Definition: A matrix is a concise and useful way of uniquely representing and working with linear transformations. In particular, for every linear transformation, there exists exactly one corresponding matrix, and every matrix corresponds to a unique linear transformation. Matrices have wide-ranging applications in such areas as image processing, information retrieval, computer graphics, scientific visualization, dynamical systems, etc. In this assignment, you are dealing with the sparse matrix of order n , which has only a small number ( t ) of non-zero elements. In the class, we have learned how a sparse matrix is represented as a set of order triplets and also learned about two algorithms for obtaining its transpose (see the lecture notes). The time-efficiency of the brute-force transpose algorithm is O ( nt ) whereas that of the fast-transpose algorithm is O( n + t ). Project Task: You will implement a sparse matrix ADT containing various functions to do the following tasks. You can use C/C++ or JAVA programming language. Read each input matrix Mnxn.mat. The values of n and t are given in the first line of the input matrix M. Find the transpose of the matrix M using the naïve (brute-forces) algorithm. Find the transpose of the matrix M using the fast-transpose algorithm. Print the original matrix ( M ) and its transpose matrix ( M' ) in the cases of small input sizes. Compute the time taken to find the transpose ( M' ) using each algorithm in all input cases using one of the two ways (see the section 2.6 of the textbook for more information). One way is to count the number of times the basic operation is executed by putting a counter within the innermost loop. The other way is to measure the actual execution time by using the clock function. However, since the algorithms run very fast for the input sizes given, you need to write and insert some delay function within the innermost loop. The delay function can be a simple loop doing nothing. Note that in the case of the fast-transpose algorithm, you might need to insert the counter or delay function in more than one part of the algorithm. Once you have all these functions ready, you will read a 5 by 5 matrix from a file called M5x5.mat , find the transpose of this matrix using the brute-force and fast-transpose

algorithms. You will then print the input matrix as well as its transpose and the time taken to compute the transpose using each algorithm. You will repeat the process for M10x10.mat and print the transpose as well. For matrices of dimensions, 20x20, 40x40, 60x60, 80x80 and 100x100 measure the time taken by both algorithms but do not print the matrices. Copy the required matrix input files from the server classes.csc.lsu.edu from /classes/cs3102/cs3102_kar/Karki-Fall09/prog Use the following command from your home directory to copy the files: cp -r /classes/cs3102/cs3102_kar/Karki-Fall09/prog. Make sure that you leave space between prog1 and dot. Output: Your output should be formatted as: Matrix M


5 5 11 0 3 297 1 0 230 1 4 291 2 0 390 2 2 250 2 3 286 2 4 330 3 2 333 3 4 464 4 0 184 4 3 347 Matrix M' using brute-force


5 5 11 0 1 230 0 2 390 0 4 184 2 2 250 2 3 333 3 0 297 3 2 286 3 4 347 4 1 291 4 2 330 4 3 464 Time: xxx.xx units Matrix M' using fast-transpose