Assigned | 20 Nov 2002 | |
Due | 10 Dec 2002 by 11:59PM | |
Updates | 21 Nov 2002 - Because the sample graph below contains no cycles each node is its own strongly connected component, as indicated by the associated sample output. |
Recall from class that a strongly connected component in a directed graph is a subset of the vertices such that a path exists from each element of that set to every other element. Also, a topological sort of a directed graph is an ordering of the vertices such that if (u, v) is an edge in the graph then vertex u occurs before vertex v in the ordering. Only graphs without cycles can be topologically sorted.
The description for this project is intentionally much less specific than the descriptions for the previous four projects. At this point in the semester you should have a well developed sense for how to design and implement classes. Spend time working out design details before you start coding.
As usual, be sure to answer the questions posed in the following file and to submit your answers along with your code: /afs/umbc.edu/users/o/a/oates/pub/CMSC341/Proj5/341-Fall02-p5_questions.txt
Cycles - A directed graph contains no cycles if and only if DFS yields no back edges. Recall that edge (u, v) is a back edge if and only if
d[v] < d[u] < f[u] < f[v]You need to write a routine that takes a graph in which the vertices have discover and finish times as computed by DFS and checks to see if any of the edges are back edges. If there are one or more back edges, the graph contains one or more cycle, otherwise it does not.
Topological sorting - Do not use the algorithm in the text for topological sorting. Instead, you will simply print nodes in the graph in reverse order of finish times.
Strongly connected components - Given graph G, let G' be the graph obtained by reversing the direction of all of the edges in G. Then the following algorithm finds the strongly connected components of G:
STRONGLY-CONNECTED-COMPONENTS(G) 1. run DFS on G to compute finish times 2. compute G' 3. run DFS on G', but when selecting which node to vist do so in order of decreasing finish times (as computed in step 1) 4. output the vertices of each tree in the depth-first forest of step 3 as a separate strongly connected componentNote that the DFS algorithm on slide 16 of the lecture notes is actually two algorithms. The first of these algorithms loops over all of the vertices in the graph and starts a DFS from each vertex that has not yet been discovered. Typically, in this loop you can iterate over the vertices in any order. However, in step 3 of the algorithm for discovering strongly connected components, you must iterate over them in order of decreasing finish times as computed in step 1. The second algorithm on slide 16 runs DFS starting from a given vertex and outputs a list of vertices visited. Every such list of vertices corresponds to a strongly connected component in step 4 of the algorithm above.
All classes that you design and implement must support the "Big-4", even if the default behavior provided by the compiler would be acceptable - default constructor, destructor, copy constructor, assignment operator.
You will need to implement at least the following classes:
4 3 0 1 1 3 0 2The graph that it describes looks like this:
0 ------> 1 | | | | | | v v 2 3The number of nodes will always be an integer greater than zero. The number of edges will always be an integer greater than or equal to zero. If the file says there are M nodes and N edges, there will always be N + 2 lines in the file and lines 3 through N+2 will contain a pair of integers between 0 and M - 1.
For the graph above, your output might look like this:
The graph does not contain any cycles. Topological sort: 0 1 3 2 Strongly connected components: 0 1 2 3NOTE: There may be multiple valid topological sorts for a graph, as there are for the graph above. Also, if the graph is acyclic, it can be toplogically sorted, but no strongly connected component will contain more than one node. If the graph has cycles, it cannot be topologically sorted, but some strongly connected component will contain more than one node.
If you don't submit a project correctly, you will not get credit for it. Why throw away all that hard work you did to write the project? Check your submittals. Make sure they work. Do this before the due date.
Documentation for the submit program is on the web at http://www.gl.umbc.edu/submit/. One of the tools provided by the submit program is submitls. It lists the names of the files you have submitted.
Additionally, there are two programs for use only by CMSC-341 students
(not part of the UCS submit program). They are in the directory
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/ and are
named submitmake and submitrun. You can use
these programs to make or run your submitted projects.
The syntax is similar to that for submit:
submitmake <class> <project>
Example: submitmake cs341 Proj5
This makes the project, and shows you the report from the make utility. It cleans up the directory after making the project (removes .o files), but leaves the executable in place.
submitrun <class> <project> [command-line args]
Example: submitrun cs341 Proj5 test.dat
This runs the project, assuming there is an executable (i.e. submitmake
was run successfully).
Project grading is described in the Project Policy handout.
Your answers to 341-Fall02-proj5_questions.txt are worth 10% of your project grade.
Cheating in any form will not be tolerated. Please re-read the Project Policy handout for further details on honesty in doing projects for this course.
Remember, the due date is firm. Submittals made after midnight of the
due date will not be accepted. Do not submit any files after that time.