Hi Team, urgent!! urgent!! urgent!! Write a program to count the number of triangles in a graph using the triangle counting algorithm and compute the local clustering coefficient of the vertices in a graph. Mentioning down a sample code. Please run the code solve the errors if any and also append the computation of local clustering coefficient code to the program and provide the output screen shot. Note: Use an input as a file and it should be a data set. Code: Please check if the below code is working or not. If not, please provide a working code. #include #include #include using namespace std; // Let the number of vertices in the graph equal to 0 at first. int V = 0; // Utility function for matrix // multiplication void multiply(int **A, int **B, int **C) { #pragma omp for // do the matrix multiplication in parallel for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { C[i][j] = 0; for (int k = 0; k < V; k++) { C[i][j] += A[i][k]*B[k][j]; } } } } // Utility function to calculate // trace of a matrix (sum of // diagonal elements) int getTrace(int **graph) { int trace = 0; for (int i = 0; i < V; i++) { trace += graph[i][i]; } return trace; } // Utility function for calculating // number of triangles in graph int triangleInGraph(int **graph) { int **aux2 = new int*[V]; // int aux2[V][V] to store graph2 int **aux3 = new int*[V]; // int aux3[V][V] to store graph3 for(int i = 0; i < V; i++) { aux2[i] = new int[V]; aux3[i] = new int[V]; } // Initialising aux // matrices with 0 for (int i = 0; i < V; ++i) for (int j = 0; j < V; ++j) aux2[i][j] = aux3[i][j] = 0; // aux2 is graph^2 now printMatrix(aux2); multiply(graph, graph, aux2); // after this multiplication aux3 is graph^3 printMatrix(aux3); multiply(graph, aux2, aux3); int trace = getTrace(aux3); return trace / 6; } int main() { // calculate the total run time of the program clock_t start, end; start = clock(); int count = 0; // the total number of triangle in the given graph int numVertex = 0; // the number of vertices in the give graph int num=0; int c = 0; //read the value of numVertex from data.txt ifstream infile; infile.open("data.txt"); infile >> numVertex >> num; cout<<"ver:"<>a>>b; graph[a][b] = 1; } // call function to calculate the value of triangle in the graph count = triangleInGraph(graph); cout <<"The total number of triangles in the given graph is: " << count << endl; end = clock(); cout <<"System run time: "<< (double) (end - start) / CLOCKS_PER_SEC << "(s)"; return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hi Team, urgent!! urgent!! urgent!!

Write a program to count the number of triangles in a graph using the triangle counting algorithm and compute the local clustering coefficient of the vertices in a graph.

Mentioning down a sample code. Please run the code solve the errors if any and also append the computation of local clustering coefficient code to the program and provide the output screen shot.

Note: Use an input as a file and it should be a data set.

Code: Please check if the below code is working or not. If not, please provide a working code.

#include <iostream>
#include <fstream>
#include <omp.h>

using namespace std;

// Let the number of vertices in the graph equal to 0 at first.
int V = 0;

// Utility function for matrix
// multiplication
void multiply(int **A, int **B, int **C)
{
#pragma omp for // do the matrix multiplication in parallel
for (int i = 0; i < V; i++)
{
for (int j = 0; j < V; j++)
{
C[i][j] = 0;
for (int k = 0; k < V; k++)
{
C[i][j] += A[i][k]*B[k][j];
}
}
}
}


// Utility function to calculate
// trace of a matrix (sum of
// diagonal elements)
int getTrace(int **graph)
{
int trace = 0;

for (int i = 0; i < V; i++)
{
trace += graph[i][i];
}

return trace;
}

// Utility function for calculating
// number of triangles in graph
int triangleInGraph(int **graph)
{
int **aux2 = new int*[V]; // int aux2[V][V] to store graph2
int **aux3 = new int*[V]; // int aux3[V][V] to store graph3

for(int i = 0; i < V; i++)
{
aux2[i] = new int[V];
aux3[i] = new int[V];
}

// Initialising aux
// matrices with 0
for (int i = 0; i < V; ++i)
for (int j = 0; j < V; ++j)
aux2[i][j] = aux3[i][j] = 0;

// aux2 is graph^2 now printMatrix(aux2);
multiply(graph, graph, aux2);

// after this multiplication aux3 is graph^3 printMatrix(aux3);
multiply(graph, aux2, aux3);

int trace = getTrace(aux3);
return trace / 6;
}

int main() {

// calculate the total run time of the program
clock_t start, end;
start = clock();

int count = 0; // the total number of triangle in the given graph
int numVertex = 0; // the number of vertices in the give graph
int num=0;
int c = 0;

//read the value of numVertex from data.txt
ifstream infile;
infile.open("data.txt");
infile >> numVertex >> num;

cout<<"ver:"<<numVertex<<" num: "<<num<<endl;

V = numVertex;

// generate the 2-D matrix for the graph
int **graph = new int*[V];
for(int i = 0; i < V; i++)
{
graph[i] = new int[V];
}

int a, b;
// read graph from adjacent matrix
for(int i = 0; i < num; i++)
{
infile>>a>>b;
graph[a][b] = 1;
}

// call function to calculate the value of triangle in the graph
count = triangleInGraph(graph);

cout <<"The total number of triangles in the given graph is: " << count << endl;

end = clock();
cout <<"System run time: "<< (double) (end - start) / CLOCKS_PER_SEC << "(s)";

return 0;

}

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY