next up previous


CSE 2320 Section 501 Fall 1998

Program 4

Due: November 24, 1998, 5:30pm (November 25, 1998, 5:00pm for -10%)

For this program you will implement a graph cycle detector. The program will input a directed graph and output all simple cycles (see p88), if any, that exist in the graph. Specifically,

1.
Your program may use no global variables.

2.
Implement a graph data structure (either adjacency matrix or adjacency list) to hold the directed graph. The graph must be allocated and deallocated at runtime. Implement procedures for graph allocation, graph deallocation, edge addition and edge lookup.

3.
Implement procedures for detecting (and outputting) cycles in a given graph. A cycle should be output as a directed path starting from the smallest vertex number, e.g., '1 -> 2 -> 3 -> 5 -> 1'. Cycles should be output in non-decreasing order by their starting vertex, where cycles beginning with the same vertex can be output in any order. If the graph contains no cycles, then simply output 'No cycles'.

4.
The main part of your program will read in data from a file whose name is given as the first argument to your executable. The first line of the file contains the number of vertices (1-100) and edges (1-1000) in the graph. The remaining lines define the edges in the graph in the form 'e 5 3', which means there is a directed edge in the graph from vertex 5 to vertex 3. Your main program should read in the graph and then call your procedure to output any cycles. See files pgm4in and pgm4out in the class directory on omega for an example. Your output should match the format of the example output.

5.
Be sure to properly document your source code, as described in Program 1. After ensuring that your program compiles and executes correctly on the omega machine, run the program /public/cse/2320-501/handin4 to electronically hand in your source file. All source code must be in one file (i.e., no separate .h and .c files). Do not turn in a printout of your source code in class.


next up previous