Question: Write a program DFSTrace that contains a version of a depth first search that prints a trace of its traversal. Write a public static method:
Write a program DFSTrace that contains a version of a depth first search that prints a trace of its traversal. Write a public static method:
public static void dfsPrintTrace(Graph g) { // *** Declare and initialize the marked array. dfsPrintTrace(g, 0, marked, 0); } This method calls a private method:
private static void dfsPrintTrace(Graph g, int start, boolean[] marked, int indent)
All references to a method below refer to this second method. Every message printed should be preceded by the number of spaces specified by the indent parameter. A recursive call should pass an indent value with 1 added.
The first time the method visits a vertex, it should print the message "First time at vertex n", where n is the integer label of the vertex.
Every other time it visits a vertex, it should print the message "Visiting vertex n again".
When it exits, it should print the message "Finished searching from n".
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
