Question: public class Graph3 {private boolean adjMatrix[][]; private int numVertices; public Graph3(int numVertices) { } // Add edges public void addEdge(int i, int j) { adjMatrix[i][j]

public class Graph3 {private boolean adjMatrix[][]; private int numVertices; public Graph3(int numVertices) { } // Add edges public void addEdge(int i, int j) { adjMatrix[i][j] = true; adjMatrix[j][i] = true; } // Print the matrix public String toString() { StringBuilder s = new StringBuilder(); for (int i = 0; i < numVertices; i++) { s.append(i + ": "); // Adding the vertices { s.append((j ? 1 : 0) + " "); } s.append(" "); } return s.toString(); } public static void main(String args[]) { Graph3 g = new Graph3(5); g.addEdge(0, 1); g.addEdge(0, 4); g.addEdge(1, 0); g.addEdge(1, 4); g.addEdge(1, 3); g.addEdge(3,2); g.addEdge(3,4); g.addEdge(4, 0); g.addEdge(4, 1); g.addEdge(4,3); System.out.print(g.toString()); } }

The code template for the assignment is provided above. A few coding statements are missing, You will fill in these statements and code for representing a graph through the adjacent Matrix. Your graph will have 6 vertices and 7 edges.

You can choose which edge will connect which vertex.

You will also draw the graph.

Your code should have annotations

Take the screenshots of your code, outputs, and diagram of your graph convert them into pdfs and upload them here.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!