Question: The depth-first search algorithm described in Listing 28.8, Depth-First Search Algorithm, uses recursion. Design a new algorithm without using recursion. Describe it using pseudocode. Implement

The depth-first search algorithm described in Listing 28.8, Depth-First Search Algorithm, uses recursion. Design a new
algorithm without using recursion. Describe it using pseudocode. Implement it by defining a new class named UnweightedGraphWithNonrecursiveDFS that extends UnweightedGraph and overriding the dfs method. Write a test program same as Listing 28.9, TestPFS.java, except that UnweightedGraph is replaced by UnweightedGraphWithNonrecursiveDFS.


Data from Listing 28.8,

Input: G = (V. E) and a starting vertex v Output: a

Data from Listing 28.9,

DFS tree rooted at v 1 SearchTree dfs (vertex v) { 2

Input: G = (V. E) and a starting vertex v Output: a DFS tree rooted at v 1 SearchTree dfs (vertex v) { 2 visit v: for each nei ghbor w of v 1f (w has not been visited) { set v as the parent for w in the tree;: dfs (w) : 3 4 6 8 }

Step by Step Solution

3.51 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilArrayList import javautilList import javautilStack public class Exercise2803 public static void mainString args String vertices Seattle San Francisco Los Angeles Denver Kansas City Chic... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Java Programming and Data Structure Questions!