Structures
Structures
Due dates.
Team formation: by 5pm on Thursday, June 14, 2024
Full assignment: by class time on Tuesday, June 18, 2024 (electronic)
in class on Friday, Oct 24, 2003 (on paper; see instructions)
Logistics.
For this wet (programming) assignment, you need to work in a team with one other
person in the class. It is up to you to decide who that person will be.
We require that one of the two students in each team email both TAs (and CC their
teammate) by 5pm on Thursday, Oct 16 letting us know the following:
(a) who the team members will be – names and email addresses for both; and
(b) what implementation language (Java or C++) both of you are going to be
using.
Note: If you fail to notify us on time, we will deduct 10% of your score on this
assignment.
The element in cell (2,1) is the first non-zero element on row 2. It is pointed to
by the header element for that row. The next non-zero element on row 2 is in cell
(2,4), to which there is a pointer from cell (2,1). The element in cell (2,4) is
also the first non-zero element in column 4. It is pointed to by the header element
for that column. Finally, row 1 and column 0 have no non-zero elements.
2
5) write(A,f) – writes a sparse matrix A out to file f, following the same
format as in the input file (see the next section). (Hint: You need to make it
possible to read in a file that was previously written to.)
This operation, similarly to read(A,f), needs to have time complexity
O(n+m+kA), not O(m*n).
Hint: You may find it useful to implement other helper routines in your sparse
matrix class, e.g., create(A,m,n), getNumRows(A),
getNumColumns(A), etc.
2. Testing. To test your sparse matrix implementation, you will need to write a
simple test module (program) that uses all of the above operations to perform
computations on matrices whose data come from the provided (and maybe also
from your own) test case files.
3. Special cases. Think about how you would deal with special cases, like a sparse
matrix with some or all of its elements becoming 0 as a result of an operation.
Does that affect, and if so – how, the way you store the matrix, or the time and
space complexities of any further operations on such a matrix? Be sure to discuss
these questions in your submission.
Test cases.
We will provide test case files having the following format:
- Rows starting with the pound sign (#) contain comments and should be
disregarded by your program.
- The first row that does not start with a pound sign defines the size of the matrix
(number of rows and columns) as well as the number of non-zero elements in
it. For example,
m = 3 n = 10 numItems = 18
means that the matrix has 3 rows, 10 columns and 18 non-zero elements (of the
30 total elements).
An exception to this is when there is a scaling (constant) factor like in the
operation mult(A,c). Then the test case file will indicate the value of that
constant factor, so the corresponding row will look, for example, like this:
m = 3 n = 10 numItems = 18 const = 376
- Each row after this first defining row contains information about exactly 1
non-zero element – the row and column coordinates of the cell where it is
stored, and its value. For example,
2,8 = 5708
means that the element in row 2 and column 8 has value 5708.
- The elements in the test files are ordered by column first, and then by row.
That is, element (4,1) would precede element (2,3) (since column 1
comes before column 3), which itself would precede element (5,3) (since
3
both have the same column 3 but row 2 precedes row 5). Look at the test case
files for more examples.
Development environment.
As an implementation language you are allowed to use either Java or C++. Be sure
to avoid using features that are specific to a particular version of a compiler, since if
you do so we likely will be unable to compile your code and you will lose points.
A description of the UW facilities you can use for this and future wet assignments
can be found on the course web page under “Assignments”.
Submission.
The submission is electronic and part of it is also paper-based, as specified below.
We need only one electronic submission and only one printed submission per team.
4
emails here. You are encouraged to work on all parts together, and if so,
indicate that this is indeed the case. If, however, you decided to split the
work, we also need to know that, as well as how you did it. Put this
description in a plain text file, called contributions.txt.
Quality criteria.
For full credit, you need to meet the following quality criteria:
1) Your submission needs to contain all parts described in the previous section.
2) Your code needs to:
- Compile and run without errors or warnings. (We will follow the
instructions you will have provided us with, so those need to be accurate.)
- Give the same results on the test cases as the test results provided by us
(unless you found an error in our test results).
- Contain comments, making it easier for a human to understand what you
have done.
3) Your argumentation about the time and space complexities of all operations
needs to be sound. Brevity is encouraged but not at the expense of clarity or
soundness.
4) Your printed materials need to look professional (i.e., be printed and stapled
together rather than hand-written and loose).
Our advice.
Be sure to start early, as this first programming assignment may prove more
challenging that you expect.