First off…here’s the problem…
Give an example of a directed graph G = (V, E), a source vertex s in V, and a set of tree edges F contained in E, such that for each vertex contained in V, the unique simple path in the graph (V, F) from s to v is a shortest path in G, yet the set of edges F cannot be produced by running BFS on G, no matter how the vertices are ordered in each adjacency list.
Now…since this IS homework, I don’t want a straight-out answer, but more of ideas for things to look at/try. But, here’s what I’ve thought of so far…
I’ve basically figured that I can create a graph that has several shortest paths to a particular vertex. Of course, one of those paths would be found in the BFS. But, I can use one of the alternate routes to fit into F. However, the part that is throwing me off is the “no matter how the vertices are ordered”… I’m not sure how to include that in to my process. I’ve tried loops, various different directional flows, and nothing yet.
Any other ideas?
I am not sure whether you are just to find a counter-example, or find an algorithm running on any given graph. Finding a counter-example is not very difficult, for example,
The source is 0. The edge set F contains (0,1) (0,2), (1,3), (2,4). F cannot be produced by BFS.
I haven’t found a general algorithm for any graph, but maybe the above sample can provide a clue.