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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started