Question: In Lecture 1 7 , we saw a magic trick that can turn a BFS algorithm into a DFS algorithm by simply replacing the queue

In Lecture 17, we saw a magic trick that can turn a BFS algorithm into a DFS algorithm
by simply replacing the queue with a stack. But I mentioned that this magic trick does not
work for all BFS algorithms. In this problem, we will see why.
Below is the BFS algorithm from Lecture 16, but with the queue replaced by a stack
attempting to make it into a DFS. Find a counterexmaple, i.e. construct a graph G=
(V,E)(can be either directed or undirected), such that for some vertex sinV, running
DFS-VISIT(G,s) does not correctly give you a DFS tree. The issue is with the sequence
of vertices that you visit, so you may safely ignore the teal-colored lines for the distances.
You should specify the graph G(drawing it out is fine) and the vertex s that you run
DFS on, along with a quick explanation of what goes wrong with the (incorrect) DFS tree
it produces.
In Lecture 1 7 , we saw a magic trick that can

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Programming Questions!