You are on page 1of 5

ASSIGNMENT

TECHNOLOGY PARK MALAYSIA


CT077-3-2 DSTR
DATA STRUCTURES
UC2F1508CS / UC2F1508SE / UC2F1508IS
HAND OUT DATE: 1 APRIL 2016
HAND IN DATE:

30 MAY 2016

WEIGHTAGE:

60%

INSTRUCTIONS TO CANDIDATES:
1

Submit your assignment at the administrative counter

Students are advised to underpin their answers with the use of


references (cited using the Harvard Name System of Referencing)

Late submission will be awarded zero (0) unless Extenuating


Circumstances (EC) are upheld

Cases of plagiarism will be penalized

The assignment should be bound in an appropriate style (comb bound


or stapled).

Where the assignment should be submitted in both hardcopy and


softcopy, the softcopy of the written assignment and source code
(where appropriate) should be on a CD in an envelope / CD cover and
attached to the hardcopy.

You must obtain 50% overall to pass this module.

Version 1.2 UCTI AssCv 2007-10-23

Data Structures

Individual Assignment

Page 1 of 4

LINKED DATA STRUCTURE for SPARSE MATRICES


A sparse matrix is a matrix populated primarily with zeros, and only a small number of its
elements have non-zero value.
Large sparse matrices often appear in scientific and
engineering applications, and being able to efficiently
process such matrices can have significant impact on
these applications and their usage.
In C++, a matrix of integer numbers can be defined
as a two-dimensional array, like int M [10] [10];.
However, such representation is not efficient for
memory usage because it consumes a lot of memory
to store very little data, since we already know the
majority of values in a sparse matrix are zeros.
Fig. 1. Sparse Matrix Example of size 10 x 10

A better representation for a


sparse matrix uses Linked
Nodes data structure to store
only non-zero values of the
matrix.
One possibility to do that is
illustrated in Fig. 2, which
shows how the matrix in Fig.1
can be represented with much
less memory usage. It uses
column nodes to store matrix
values, and row nodes to link
the different rows together, and
to access all column nodes of
a particular row.
Each row or column node
contains an indicator to the
corresponding row-index or
column-index of the matrix.

6 1

1 3

5 7

2 2

9 7

0 9

3 5

0 2

1 6

2 7

Indicates
row no.

Pointer to the next nonzero element in that row

7 8

Indicates column no.


Indicates non-zero value

7 5

Pointer to first element in the list (i.e.


first non-zero element in that row)
Pointer to the next non-all-zero row of the matrix

Fig. 2. Sparse Matrix Represented using Linked Nodes

You are required to write a C++ program that implements the given sparse matrix data
structure, with the following functionalities:

Degree Level 2

Asia Pacific University of Technology and Innovation

2016

Data Structures

Individual Assignment

Page 2 of 4

1. Suitable class(es) to represent a sparse matrix (SM) using the data structure explained
above:
class SM{
int n; int m;

//

# rows, # columns

//

and other necessary data members

public:
SM ( int rows, int columns );
~SM ( );
void readElements ( );
void printMatrix ( );
SM * addSM ( SM & other );
};
//

and other classes, if necessary.

2. A constructor that creates an nm matrix from given parameters:


SM ( int rows, int columns ) { }

creates the dynamic structure, if necessary, and properly initializes it.

3. Read function to allow user to input the non-zero elements of the matrix:
void readElements ( ) { }

reads only the non-zero elements from the user, and properly fills in the
corresponding nodes, and links them correctly. User should keep inputting
arbitrary [row index, column index, and value] triples, with proper indicator to stop
input process.

4. Printing function to show content of a sparse matrix:


void printMatrix ( ) { }

prints a tabular form showing all zero and non-zero elements of the matrix
(something like Fig. 1)

5. Add function to sum two sparse matrices:


SM * addSM ( SM & other ) { }

takes another sparse matrix parameter (which must have same dimensions) and
returns a pointer to a newly created sparse matrix object, whose values are the sum
of corresponding elements of the two matrices (this and other).

6. A destructor to free the dynamic memory allocated for a matrix:


~ SM ( ) { }

properly frees any dynamically allocated memory for the sparse matrix object.

Degree Level 2

Asia Pacific University of Technology and Innovation

2016

Data Structures

Individual Assignment

Page 3 of 4

7. Main driver function to test / validate the whole program:


-

a suitable code that interacts with the user to test the working of all functionalities,
by at least reading two matrices, printing them, and printing their sum.

Assignment Requirements
You are required to submit a hardcopy as well as a softcopy of assignment report and
source code. The report should contain:
- Detailed explanation of the data structures and classes created, with proper
justification on your decisions (include source code defining classes, data members,
and method headers only).
- Brief explanation about the algorithms used to implement functionalities 2, 3, 4, 5,
and 6 above (include code snippets of important parts of implementation).
- Source code of the main function, with screenshots showing programs input and
output interactions.
You have to present your assignment solution and answers to the lecturer during Q&A
session that will be conducted after hand-in date.
If you use some code which has been taken or adapted from another source (book,
magazine, internet, forum, etc.) then this must be cited and referenced using Harvard
Referencing Style within your source code, and this must be mentioned explicitly in the
report. Failure to reference code properly will be treated as plagiarism.
Automated tools for checking code similarities among submissions will be used, and
all detected cases will be treated as cheating.
Assessment marks are divided as follows:

Marks %

Implementation Quality

Documentation

Presentation

60%

10%

30%

What You Need to Hand In?


1.

You are required to hand in the individual assignment report on or before the due
date mentioned on the cover sheet of the assignment.

2.

The attached CD should include a softcopy of the report, in addition to the C++
files of the programs. The organization of files and folders must adhere to the
following instructions precisely:
A folder named StudentFirstName-StudentID-Asmnt should contain the
report file (Microsoft Word), and the C++ (*.cpp / *.h) files ONLY. All
additional project files (especially if you use Visual Studio) should be removed.
Make sure to DELETE all non-source-code files, including executables (*.exe).

3.

A zipped file containing CD content and named StudentFirstName-StudentIDAsmnt.zip should be emailed to the lecturer at dr.asem.kasem@apu.edu.my on
submission day itself. The email subject field MUST be set to: DSTR
Assignment - Full Name - StudentID. Failing to send the email on time, or not
following the given guidelines will be considered as no submission.

Degree Level 2

Asia Pacific University of Technology and Innovation

2016

Data Structures

4.

Individual Assignment

Page 4 of 4

You should present an executable solution during Q&A session to demonstrate


program execution, the working of the data structure, your understanding of the
code, and ability to modify / fix it.
You have to submit your assignment with Coursework Submission and Feedback
Form (CSFF) attached.

5.

Marking Criteria:
The program submitted will be evaluated according to the following performance criteria:
Distinction (90% and above)

Program compiles and executes perfectly


At least 90% of the required functionalities are correctly implemented
Efficient data structures and\or algorithms are used in the implementation
Clear coding style and structure, and code is properly commented
Functionalities are fully tested/validated in program execution

Credit (70% 89%)

Program compiles and executes


Between 70% and 90% of the required functionalities are correctly implemented
Implementation uses a data structure or algorithm that is not most efficient
Clear coding style, and code is properly commented
Functionalities are not fully tested/validated in program execution

Pass (50% - 69%)

Program compiles perfectly and executes


Between 50% and 70% of the required functionalities are correctly implemented
Implementation uses inefficient data structures or algorithms
Unclear coding style, or code is not properly commented
Functionalities are not full tested/validated in program execution, or produce
errors in some cases

Marginal Fail (30% - 49%)

Program does not compile or run, but coding logic is almost correct
Between 30% and 50% of the required functionalities are correctly implemented
Implementation uses inefficient data structures or algorithms
Unclear coding style, and no comments provided
Functionalities are not tested/validated in program execution

Fail (below 30%)

Program is not given


Program does not compile or run
Less than 30% of the required functionalities are implemented
Implementation uses very inefficient data structures or algorithms
No proper code structure and no comments provided

Degree Level 2

Asia Pacific University of Technology and Innovation

2016

You might also like