Question: public class Graph 1 { private boolean adjMatrix [ ] [ ] ; private int numVertices; public Graph 1 ( int numVertices ) { this.numVertices
public class Graphprivate boolean adjMatrix;
private int numVertices;
public Graphint numVertices
this.numVertices numVertices;
adjMatrix new booleannumVerticesnumVertices;
Add edges
public void addEdgeint i int j
adjMatrixij true;
adjMatrixji true;
public String toString
StringBuilder s new StringBuilder;
for int i ; i numVertices; i
sappendi : ;
;
return stoString;
public static void mainString args
Graph g new Graph;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
gaddEdge;
System.out.printgtoString;
Almost all the code for representing graph through adjacency matrix is provided. Only few objects are missing.
Your assignment:
Fill in the missing codes and program adjacency matrix to represent graph
Represent a graph having vertices, you can choose your source and destination vertices
In a separate piece of paper explain the code and draw the graph that you have coded
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
