Please fill out this quiz, and press the "Submit" button at the end. Don't collaborate with anyone on quiz exercise solutions.
Please answer all questions.
SID: [No spaces and no dashes.]
Login ID :
1. The BFS algorithm shown in class only inserts a vertex v into the queue if (a) the vertex has not been visited before, and (b) the vertex is not already in the queue. Suppose that we remove these restrictions. Would the modified algorithm still visit every node that is reachable from the starting point?
In other words, the modified algorithm is as follows:
Modified-BFS(G,s): 1. Mark s. 2. Create an empty list Q, and insert s into Q. 3. While Q is not empty: 4. Remove the node from the front of Q; call it u. 5. for each edge (u,v) in E: 6. Append v to the end of the list Q (whether or not v is already marked, and whether or not v is already in Q). 7. Mark v.
Are we guaranteed that Modified-BFS(G,s) will eventually visit every node that is reachable from s? Explain briefly.
If you say "yes", explain why briefly. If you say "no", explain why briefly; how bad could the asymptotic running time be, as a function of |V|, a function of |E|, or a function of both |V| and |E|?
Clarification added 2/22: If you say "no", it's fine to give a rough lower bound for the worst-case asymptotic running time as a function of |V|, or as a function of |E|, or as a function of both |V| and |E| (your choice). Don't spend too long on this. (You don't have to give a complete characterization of the worst-case running time when running Modified-BFS(G,s) on dags with exactly n vertices and exactly m edges, for every n,m.)