* Use adjacency Matrix to implement an undirectedGraph*/
public class GraphAdjacencyMatrix {
protected int maxVertsNum; // maximum number of vertices in thegraph, i.e., the size of the array vertexList
protected int numVerts; // current number of vertices in thegraph
protected Vertex [] vertexList;
protected int [][] adjMatrix;
public GraphAdjacencyMatrix(int maxVerts){
// The constructor, initialize all variable. Initialize all entriesin matrix as 0
}
public void addVertex(char label){
// ad vertex to vertexList
}
public void addEdge(int start, int end){
// add edge to the undirected graph
}
public boolean hasEdge(int src, int dest) {
// return true in src and dest are connected
}
public void displayAllEdges(){
}
public static void main(String[] args) {
GraphAdjacencyMatrix graph = new GraphAdjacencyMatrix(5);
graph.addVertex(‘A’); //0
graph.addVertex(‘B’); //1
graph.addVertex(‘C’); //2
graph.addVertex(‘D’); //3
graph.addEdge(0, 1);
graph.addEdge(0, 2);
graph.addEdge(1, 2);
graph.addEdge(2, 3);
graph.displayAllEdges();
System.out.println(“Is there an edge between”+graph.vertexList[0].label+” and “+graph.vertexList[2].label+” =”+graph.hasEdge(0, 2));
System.out.println(“Is there an edge between”+graph.vertexList[1].label+” and “+graph.vertexList[3].label+” =”+graph.hasEdge(1, 3));
}
}
class Vertex{
public char label;
public boolean isVisited = false;
public Vertex(char label){
this.label = label;
}
}
Expert Answer
Answer to * Use adjacency Matrix to implement an undirected Graph*/ public class GraphAdjacencyMatrix { protected int maxVertsNum;…