CSE 4081/5081 Analysis of Algorithms
Fall 1997 -- Proejct 1
Assigned September 8, 1997 -- Due October 6, 1997

Graph reachability is a classic problem with many applications in the real-world. A finite directed graph tex2html_wrap_inline10 is a finite set V of vertices and a set E of edges which are ordered pairs of vertices. Graph reachability is the decision problem: Given a graph G and two vertices tex2html_wrap_inline18 , is there a path from 1 to n?

A simple search algorithm can be used to solve an instance of reachability works as follows: Throughout the algorithm a set of vertices, denoted by S is maintained. Initially, tex2html_wrap_inline26 . Each node can be either marked or unmarked. That node i is marked means that i has been in S at some point in the past or is currently in S. Initially, only i is marked. At each iteration of the algorithm, choose a node tex2html_wrap_inline38 and remove it from S. Process each edge tex2html_wrap_inline42 out of i. If j is unmarked, mark it and add it to S. Continue this process until S becomes empty. At this point, answer ``yes'' if n is marked and ``no'' otherwise.

The informal statements above can be written in pseudo-code.

int NO = 0;
int YES = 1;
int reachability(graph G, node a, node b) {

  for each node i of G set i to unmarked;
  set S;
  insert(a, S);
  while (notempty(S)) {
    remove node i from S;
    for each edge (i, j) in G {
      if j is unmarked {
        insert(j, S);
  if (marked(b) return YES;
  else return NO;

Your assignment is to write a report that clarifies many of the important details left out of the above discussion. In particular,

  1. How is the graph represented as input to the algorithm?
  2. How is the set S represented and how are elements tex2html_wrap_inline38 chosen among all the elements of S?
  3. How does one know that the algorithm will terminate?
  4. Given that the algorithm terminates how does one argue that is correctly answers the reachability problem?
  5. How would you measure the time complexity of the algorithm and What is the time complexity as a function of the number of nodes in the graph?
  6. Does the time complexity depend on the data structures used to represent the graph or the set of marked nodes?

Lastly, you are to write a program that implements the algorithm and execute it on several graph instances. You should be able to empirically show that the time needed to run the algorithm matches the time complexity function found above. It should not be necessary to insert explicit timing commands into the code itself, a profiler can be used to determine the time and/or number of steps needed to execute the code on a particular instance.

Your report should include a well-written discussion of the reachability problem (perhaps you can include real-world applications), answers to the above questions, a listing of your program and timing results from several runs of you program. The report is due October 6, 1997.

Florida Tech Computer Science

William D. Shoaff
Comments to author:wds@cs.fit.edu

All contents copyright ©, William D. Shoaff
Revised: Mon Sep 8 13:17:30 EST 1997