CSR: A rectangular array of numbers is called a matrix. Sometimes a matrix is referred as a table, 2-dimensional array,or array of arrays.
CSR: A rectangular array of numbers is called a matrix. Sometimes a matrix is referred as a table, 2-dimensional array, or array of arrays. Consider the following matrix below. It has 5 rows (denoted n) and 8 columns (denoted m). As you can see the row and column numbers start with a 0.
The empty cells have the same common value (it can be assumed as 0). The above matrix is said to be sparse because the total number of common values is significantly large in comparison to other non-common values in the matrix. In the example above, we have a total of 40 values in the matrix (8 ´ 5), 10 non-common/zero values, and 30 common values.
You can store such a sparse matrix in different formats which will lead to less space complexities. The one method which we are going to be implementing here is called the Compressed Sparse Row(CSR) format. In this format, the matrix n x m is stored in 3 one dimensional arrays – valueArray, IA and JA.
valueArray = [100, 900, 500, 200, 300, 400, 800, 200, 1600, 700]
IA = [0, 3, 5, 7, 8]
JA = [0, 3, 5, 4, 7, 1, 6, 2, 0, 4]
Graph and matrix correlation: A very popular data structure to store graphs is by using matrices called the Adjacency Matrix. The values in the matrices are the edge weights connecting the vertex from the corresponding row number vertex to the column number vertex. Edge existence is to determine whether there exists an edge between the vertices given.data
GetNeighbours should get all the neighbours of the node given to the method. You are also required to do a Breadth First Search and a Depth First Search on the given start node – you are required to save the sequence of this BFS and DFS on an array and return it(hence the return type for the methods is int*). You are allowed to use the queue and stack stl libraries for the implementation of these two methods. You can find more information about this in Chapter 11.5 from the book and also the videos that will be released.
All these graph operations have to be done directly on the CSR data structure(3 one dimensional arrays) and you are not supposed to un compress the data structure into a matrix for these operations.
On a higher perspective, in this project, you will create appropriate C++ classes (given in sampleMain.cpp) to create the compressed sparse matrix representation data structure and do the graph operations(edge existence, getNeighbours, DFS and BFS) on the compressed sparse row matrix.
Your project implementation: As part of this project, you will create a class names CSR as given in sampleMain.cpp. This class will have the fields which we used above to store the matrix and also other methods necessary. A sampleMain.cpp(the following code) is also given to you along with this description.
Input: You must ensure that your program outputs the output in the exact format provided in the sample outputs. The input file will be of the following format:
5 8 10// <-numRows, numColsand numNZV// <-entire input matrix16000 0 07000 0 00 3// <-verticesforedge existance2// <-vertexfor getNeighbours1// <-start vertexfor BFS and DFSThe first line reads – 5 rows, 8 columns and 10 being the number of non-sparse values in the matrix. You are also required to overload the ostream operator to display the matrices in matrix format from the CSR object. Example inputs for the above given program have been posted in canvas under the Project 2 tab.
The code must be submitted in GradeScope(more instructions on this will be made as an announcement) where they will be auto graded with the sample set of inputs and outputs and will be officially graded later with more exhaustive input files.
There is a sample hello world auto grader project setup on GradeScope for testing purposes, please go ahead and upload a HelloWorld program there. You need to print this exactly – “Hello World!” followed by a new line. And your file has to be named as ‘helloworld.cpp’. This is a test, so please upload asap and make sure it works. You should past test case 1.
Redirected input provides you a way to send a file to the standard input of a program without typing it using the keyboard. To use redirected input in Visual Studio environment, follow these steps: After you have opened or created a new project, on the menu go to project, project properties, expand configuration properties until you see Debugging, on the right you will see a set of options, and in the command arguments type <“input filename”. The < sign is for redirected input and the input filename is the name of the input file (including the path if not in the working directory). A simple sample program that reads a matrix can be found below.
#include <iostream> using namespace std; int main (){int r,c,cv,nsv; int val;cin >> r >> c >> nsv;for (int i=0; i < r; i++) {for (int j=0; j < c; j++) { cin >> value;cout<<value<<“ “;}endl;}return 0;}Constraints: