0. In the implementation for a breadth-first search we studied, a queue was used. The code below replaces the queue with a stack. List the pre-order enumeration that the vertices in the graph below are visited using this modified method, starting from vertex 0. 0 } 1 } 2 3 } 4 5 6 /** stack-based search */ static void modSearch (Graph G, int start) { Stack S = new AStack(G.n()); S.push(start); G.setMark (start, VISITED); while (S.length() > 0) { int v S.pop(); = PreVisit (G, v); 7 modSearch: for (int w = G.first (v); w < G.n(); w= G.next(v, w)) if (G.getMark (w) == UNVISITED) { G.setMark (w, VISITED); S.push(w);

icon
Related questions
Question
30. In the implementation for a breadth-first search we studied, a queue was used. The code below replaces
the queue with a stack. List the pre-order enumeration that the vertices in the graph below are visited
using this modified method, starting from vertex 0.
}
3
/** stack-based search */
static void modSearch (Graph G, int start) {
Stack<Integer> S new AStack<Integer> (G.n());
S.push(start);
}
6
G.setMark (start, VISITED);
while (S.length) > 0) {
}
modSearch:
intv S.pop();
PreVisit (G, v);
for (int w = G.first (v); w < G.n(); w = G.next(v, w))
if (G.getMark (w) == UNVISITED) {
G.setMark (w, VISITED);
S.push(w);
Transcribed Image Text:30. In the implementation for a breadth-first search we studied, a queue was used. The code below replaces the queue with a stack. List the pre-order enumeration that the vertices in the graph below are visited using this modified method, starting from vertex 0. } 3 /** stack-based search */ static void modSearch (Graph G, int start) { Stack<Integer> S new AStack<Integer> (G.n()); S.push(start); } 6 G.setMark (start, VISITED); while (S.length) > 0) { } modSearch: intv S.pop(); PreVisit (G, v); for (int w = G.first (v); w < G.n(); w = G.next(v, w)) if (G.getMark (w) == UNVISITED) { G.setMark (w, VISITED); S.push(w);
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer