(Solved) : Use Adjacency Matrix Implement Undirected Graph Public Class Graphadjacencymatrix Protecte Q42736706 . . .

* 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);
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;…

Leave a Comment


We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?