dstr assignment

Upload: mamad

Post on 05-Jul-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/16/2019 DSTR Assignment

    1/5

    Version 1.2 UCTI AssCv 2007-10-23

    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

    2 Students are advised to underpin their answers with the use ofreferences (cited using the Harvard Name System of Referencing)

    3 Late submission will be awarded zero (0) unless ExtenuatingCircumstances (EC) are upheld

    4 Cases of plagiarism will be penalized

    5 The assignment should be bound in an appropriate style (comb boundor stapled).

    6 Where the assignment should be submitted in both hardcopy andsoftcopy, the softcopy of the written assignment and source code(where appropriate) should be on a CD in an envelope / CD cover andattached to the hardcopy.

    7 You must obtain 50% overall to pass this module.

  • 8/16/2019 DSTR Assignment

    2/5

    Data Structures Individual Assignment Page 1 of 4

    Degree Level 2 Asia Pacific University of Technology and Innovation 2016

    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.

    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.

    You are required to write a C++ program that implements the given sparse matrix data

    structure, with the following functionalities:

    Fig. 1. Sparse Matrix Example of size 10 x 10 

    0 6 11 3

    5 7

    9 72 2

    3 50 9

    0 2

    1 6

    7 52 7

    7 8

    Indicates

    row no.

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

    first non-zero element in that row) 

    1

    3

    4

    5

    7

    9

    Pointer to the next non-all-zero row of the matrix 

    Indicates non-zero value 

    Indicates column no. 

    Pointer to the next non-

    zero element in that row 

    Fig. 2. Sparse Matrix Represented using Linked Nodes 

  • 8/16/2019 DSTR Assignment

    3/5

    Data Structures Individual Assignment Page 2 of 4

    Degree Level 2 Asia Pacific University of Technology and Innovation 2016

    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 n×m 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 thecorresponding 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.

  • 8/16/2019 DSTR Assignment

    4/5

    Data Structures Individual Assignment Page 3 of 4

    Degree Level 2 Asia Pacific University of Technology and Innovation 2016

    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 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

    Marks % 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-StudentID-

    Asmnt.zip” should be emailed to the lecturer at [email protected] 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 notfollowing the given guidelines will be considered as no submission.

    mailto:[email protected]:[email protected]:[email protected]

  • 8/16/2019 DSTR Assignment

    5/5

    Data Structures Individual Assignment Page 4 of 4

    Degree Level 2 Asia Pacific University of Technology and Innovation 2016

    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 structure and no comments provided