Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In the following lab task you are required to modify the Graph.java in the folder LabTask 0 1 such that it represents a graph using
In the following lab task you are required to modify the Graph.java in the folder LabTask such that it
represents a graph using adjacency matrix representation similar to the above representation.
Page of
a Complete the method: public void addEdgeint int to add an undirected edge to the graph.
Note: For an undirected graph, if an edge is added to the graph then the reverse edge i must also
be added.
b Complete the method: public void removeEdgeint int to remove an undirected edge from the
graph
Note: For an undirected graph, an edge is removed from the graph then the reverse edge i must
also be removed.
c Complete the method: public boolean isEdgeint int The method returns true if is an undirected
edge in the graph; otherwise, it returns false.
d Complete the driver class by creating the following graph:
Run the program to get an output of the following form:
public class Graph
private boolean adjacencyMatrix;
private int numberOfVertices;
public Graphint numberOfVertices
this.numberOfVertices numberOfVertices;
adjacencyMatrix new booleannumberOfVerticesnumberOfVertices;
public void addEdgeint i int j
To be completed by students
public void removeEdgeint i int j
To be completed by students
public boolean isEdgeint i int j
to be completed by students
public void displayGraph
System.out.printfs;
forint i ; i numberOfVertices; i
System.out.printfs i;
System.out.println;
forint i ; i numberOfVertices; i
System.out.printfs i;
forint j ; j numberOfVertices; j
System.out.printfs adjacencyMatrixij;
System.out.println;
public class GraphDriver
public static void mainString args
Create an undirected graph with vertices
To be completed by students
Add the edges of the graph
To be completed by students
Display the graph before deleting edge
System.out.printlnBefore deleting edge the graph is:
;
To be completed by students
Display the graph after deleting edge
To be completed by students
System.out.println
After deleting edge the graph is:
;
To be completed by students
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