Question: The following graph will be used throughout this question. a. (Given the graph classes Vertex, java and Graph.java in the Appendix, lava code for a

The following graph will be used throughout this question. a. (Given the graph classes Vertex, java and Graph.java in the Appendix, lava code for a depth-first traversal on a connected component of a graph is as follows: public void depthFirstTraversalRec1(Integer v) {//PRE: v is the id of a vertex in the graph//POST: Prints out a depth-first traversal of a graph//starting from v System. out. print(" " + v): getVertex(v). setMarked(): //get vertex object with id v, //indicate visited by setting marked VertexIDList adjList = getVertex(v). getAdjs();//get adjacency list representing neighbours Iterator vIt = adjList. Iterator(): while (vIt hasNext()) {//iterate over neighbours Integer nextVertex = vIt. next(): if (!getVertex(nextVertex).isMarked())//if neighbour hasn't been visited depthFirstTraversalRec1(nextVertex);//visit it } } Give the depth-first traversal of the graph above, starting from vertex 1. b. Using the code in a. as a starting point, give a Java function that will detect whether there is a cycle in a graph
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
