Question: 2. Answer in C language please. The adjacency matrix A of a graph has entries aij , where aij is 1 if there is an
2. Answer in C language please. The adjacency matrix A of a graph has entries aij , where aij is 1 if there is an edge between vertex i and vertex j, and 0 otherwise. The entries of An tell you the number of different walks of length n from i to j. You can calculate the number of triangles that vertex i is a part of by finding [A3 ]ii/2. Write a program that reads the adjacency matrix of a graph with 5 vertices. It should output the (1) number of triangles that each vertex is part of; (2) total number of triangles in the graph. Remember, each triangle gets counted at three vertices. Test it on the example below. 0 1 1 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 1 0 Vertex 1 is part of 3 triangles. Vertex 2 is part of 1 triangles. Vertex 3 is part of 1 triangles. Vertex 4 is part of 2 triangles. Vertex 5 is part of 2 triangles. Total 3 triangles.
2. The adjacency matrix A of a graph has entries lij, where dij is 1 if there is an edge between vertex i and vertex j, and 0 otherwise. The entries of A tell you the number of different walks of length n from i to j. You can calculate the number of triangles that vertex i is a part of by finding [A]u/2. Write a program that reads the adjacency matrix of a graph with 5 vertices. It should output the (1) number of triangles that each vertex is part of; (2) total number of triangles in the graph. Remember, each triangle gets counted at three vertices. Test it on the example below. [01111 1 0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 1 0 Vertex 1 is part of 3 triangles. Vertex 2 is part of 1 triangles. Vertex 3 is part of 1 triangles. Vertex 4 is part of 2 triangles. Vertex 5 is part of 2 triangles. Total 3 triangles
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
