CS 502 Fundamental of Algorithms Assignment # 04 Spring 2012 Total Marks = 20 Deadline Your assignment must be uploaded / submitted before or on June 19, 2012 Upload Instructions Please view the assignment submission process document provided to you by the Virtual University. Rules for Marking Please note that your assignment will not be graded if: • It is submitted after due date • The file you uploaded does not open • The file you uploaded is copied from someone else or from internet • It is in some format other than .doc Note: Material that is an exact copy from handouts or internet would be graded Zero marks. Your solution should consist of the material found through different sources and written in your own words. Assignment Statements: Question: Give an example of a directed graph G = (V, E), a source vertex s V, and a set of tree edges Eπ ⊆ E such that for each vertex v V, the unique path in the graph (V, Eπ) from s to v is a shortest path in G, yet the set of edges Eπ cannot be produced by running BFS on G, no matter how the vertices are ordered in each adjacency list. Solution: The edges in Eπ are shaded in the following graph: To see that Eπ cannot be a breadth-first tree, let’s suppose that Adj[s] contains u before v. BFS adds edges (s, u) and (s, v) to the breadth-first tree. Since u is enqueued before v, BFS then adds edges (u, w) and (u, x). (The order of w and x in Adj[u] doesn.t matter) Symmetrically, if Adj[s] contains v before u, then BFS adds edges (s, v) and (s, u) to the breadth- first tree, v is enqueued before u, and BFS adds edges (v, w) and (v, x). (Again, the order of w and x in Adj[v] doesn’t matter). BFS will never put edges (u, w) and (v, x) into the breadth-first tree. In fact, it will also never put both edges (u, x) and (v, w) into the breadth-first tree.