Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project, you will implement the matrix multiplication-based solution we saw in class to determine the number of walks of length l between any

In this project, you will implement the matrix multiplication-based solution we saw in class to determine the number of walks of length l between any two vertices. The walk length is 4 for all students. The graph on which your code has to be tested is assigned below. You are given a startup code (in C++/Java) that reads in the list of edges and sets up the adjacency matrix as a two-dimensional array. Your task would be to extend the code such that the procedure to compute the number of walks of length l is implemented. For ease of implementation, vertex ID starts with 0. Below, I show the list of edges (stored as a text file) and a screenshot of the expected output for a sample graph.

image text in transcribed

C++ code

#include

#include

#include

#include

#include

#include

#include

#include

#include // for string tokenizer and c-style string processing

using namespace std;

void printMatrix(int** matrix, int numNodes){

for (int uNodeID = 0; uNodeID

for (int vNodeID = 0; vNodeID

cout

cout

}

}

int main(){

string graphEdgesFilename;

cout

cin >> graphEdgesFilename;

int numNodes;

cout

cin >> numNodes;

int walkLength;

cout

cin >> walkLength;

int **adjacencyMatrix; // pointer to a pointer

adjacencyMatrix = new int* [numNodes]; // creating an array of pointers

for (int rowID = 0; rowID

adjacencyMatrix[rowID] = new int[numNodes]; // each pointer points to an array of elements in a row

}

for (int uNodeID = 0; uNodeID

for (int vNodeID = 0; vNodeID

adjacencyMatrix[uNodeID][vNodeID] = 0;

}

}

ifstream graphEdgeFileReader(graphEdgesFilename);

if (!graphEdgeFileReader){

cout

return 0;

}

int numCharsPerLine = 25;

char *line = new char[numCharsPerLine];

// '25' is the maximum number of characters per line

graphEdgeFileReader.getline(line, numCharsPerLine, ' ');

// ' ' is the delimiting character to stop reading the line

while (graphEdgeFileReader){

char* cptr = strtok(line, " \t");

string uNodeToken(cptr);

int uNodeID = stoi(uNodeToken);

cptr = strtok(NULL, " \t");

string vNodeToken(cptr);

int vNodeID = stoi(vNodeToken);

adjacencyMatrix[uNodeID][vNodeID] = 1;

adjacencyMatrix[vNodeID][uNodeID] = 1;

graphEdgeFileReader.getline(line, numCharsPerLine, ' ');

}

cout

printMatrix(adjacencyMatrix, numNodes);

return 0;

}

2 2 3) 2 Sample Graph edgelnfo.txt Enter the file name for the edges of the graph: edgeInfo.txt Enter number of nodes 6 Enter the walk length: 4 Initial Adjacency Matrix 0 1 0 0 0 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 1 0 0 1 0 1 0 1 1 1 0 1 0 Final Walk Length Matrix (Length 12 16 11 12 16 12 16 39 16 24 24 24 11 16 12 12 16 12 12 24 12 20 16 19 16 24 16 16 23 16 12 24 12 19 16 20 2 2 3) 2 Sample Graph edgelnfo.txt Enter the file name for the edges of the graph: edgeInfo.txt Enter number of nodes 6 Enter the walk length: 4 Initial Adjacency Matrix 0 1 0 0 0 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 1 0 0 1 0 1 0 1 1 1 0 1 0 Final Walk Length Matrix (Length 12 16 11 12 16 12 16 39 16 24 24 24 11 16 12 12 16 12 12 24 12 20 16 19 16 24 16 16 23 16 12 24 12 19 16 20

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago