CS 302 - Data Structures & Algorithms - Spring 2008
Programming Assignment 4


Loyola College > Department of Computer Science > CS 302 > Programming Assigngments > Programming Assignment 4

DFS Cycle Detection on Directed Graphs

Due

Design and Test Cases: Friday, March 28 (in email)
Code and Output: Friday, April 4 in class

Be sure to include the Honor Code Statement:
"I hereby declare that I have abided by the Honor Code during this assignment."

Introduction

Modify the implementation of either the adjacency list or matrix implementation for graphs (don't worry, you will get a chance to do the other option) to work for directed graphs. The graph will be inputted from standard in. Then use DFS from a user specified vertex to check for a cycle in the graph back to that node. If there is a cycle print it out in order using the labels provided at input (not the vertex ids).

What to hand in

  1. (by 3/28 by email) A one-page design.
  2. (by 3/28 by email) A black-box test plan.
  3. (on 4/4) A two-up listing of your code. You might use something like
    a2ps -T 4 -q -Avirtual -2 -o mycode.ps <file>
    and then preview the page breaks and general appearance using gv mycode.ps
  4. (on 4/4) A two-up print out of some annotated sample output.
  5. (on 4/4) Email me a single tar file that includes all your source files, output, makefile, and any auxiliary files that you have accumulated. Make sure to include your test plan and the output from the execution of your program on this test plan.

Notes

  1. FYI, the rest of the programming assignments will involve graphs so be sure to make sure you understand them.
  2. Your program should read the input graph from stdin.
  3. A random test graph can be piped to your program using
    /cs302/proj4/graph_gen V E Q | <your-program>
    where V is the number of vertices, E is the number of requested edges, and Q is the number of queries. This uses the random graph generator on pg 42 of the text, so it may have a few more or less edges than E.
  4. Use the following input format (the example graph is a complete graph of size 3).

    node/edge notes
    3 vertex count
    A labels are strings of no more than 255 characters
    and contain no whitespace.
    B
    C
    -1 sentinel marking end of vertices; edges next
    A B edge from vertex A to vertex B
    A C edge from vertex A to vertex C
    B A etc
    B C
    C A
    C B
    -1 -1 sentinel marking end of edges; next queries
    A check for cycle starting from vertex A
    B check for cycle starting from vertex B
    -1 end of queries