You are on page 1of 4

# Data Structures Individual Assignment Page 1 of 4

## LINKED DATA STRUCTURE for UPPER TRIANGULAR MATRICES

An Upper Triangular Matrix is one of the classifications of sparse matrix that is populated
primarily with zeros, and only a small number of its elements have non-zero value.
The standard representation of a matrix in computer science is a two-dimensional array. While
representing such matrices, memory organization plays a vital role as all the elements would not
be used to store the data in matrix array all times. Hence, consideration of an alternate forms of
representation for such matrices is required.

## In C++, a matrix of integer numbers can be defined as two-dimensional array, like

“int M [7] [7];” 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.

## A better representation for an upper triangular

matrix uses Linked Nodes data structure to store
only non-zero values above the main diagonal
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.
Fig.1: Upper Triangular Matrix
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.

## Fig.2: Memory Representation of Upper Triangular

Matrix

Fig. 1. Sparse
Matrix Example of Pointer to the next non-all-zero row of
size 10 x 10 the matrix
Fig. 2. Sparse Matrix Represented using
You are required to write a C++ program that implements the given upper triangular matrix data
structure, with the following functionalities:

## Degree Level 2 Asia Pacific University of Technology and Innovation 2018

1. Suitable class(es) to represent a upper triangular matrix (UTM) using the data structure
explained above:
class UTM{
int n; int m; // # rows, # columns
… // and other necessary data members
public:
UTM ( int rows, int columns );
~UTM ( );
void inputElements ( );
void displayMatrix ( );
UTM * sumUTM ( UTM & other );
};
// and other classes, if necessary.

## 2. A constructor that creates an n×m matrix from given parameters:

UTM ( int rows, int columns ) { … }
- creates the dynamic structure, if necessary, and properly initializes it.

3. Input function to allow user to input the non-zero elements of the matrix:
void displayElements ( ) { … }
- 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. Displaying 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. Sum function to sum two upper triangular matrix:

UTM * sumUTM ( UTM & other ) { … }
- takes another upper triangular 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:

~ UTM ( ) { … }
- properly frees any dynamically allocated memory for the sparse matrix object.
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
- 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 program’s 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:

Implementation Quality Documentation Presentation

## 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-StudentID-
Asmnt.zip” should be emailed to the lecturer at
syedmohdzahid@staffemail.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.
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.
5. You have to submit your assignment with Coursework Submission and Feedback
Form (CSFF) attached.

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