# Assignment Solution Spring 2012_CS502_4_SOL by nouman100

VIEWS: 9 PAGES: 2

• pg 1
```									             CS 502 Fundamental of Algorithms
Assignment # 04
Spring 2012
Total Marks = 20

Your assignment must be uploaded / submitted before or on June 19, 2012

Please view the assignment submission process document provided to you by the
Virtual University.

Rules for Marking
• 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