Computer Science 245
Spring 2009
Homework 7:  Sorting, Hash Tables & Disjoint Sets
Due Friday, April 10th 3:30 p.m.

For homework 7, you will need to implement the following three functions:
  1. public static void BFS(Graph G, int Parent[], int startVertex, boolean Visited[])

    A standard Breadth-First Search, except that the BFS search tree is created in the Parent[] array, using the same parent pointer representation as disjoint sets (that is, Parent[x] = index of the parent of  x, or -1 if x has no parent).  You can assume that all elements of the array Visited[] are false, and all elements of the array Parent[]  are -1 when the function is first called.  Feel free to use the provided code for Queues.

  2. public static void DFS(Graph G, int Parent[], int startVertex, boolean Visited[])

    A standard Depth-First Search, except that the DFS search tree is created in the Parent[] array, using the same parent pointer representation as disjoint sets (that is, Parent[x] = index of the parent of  x, or -1 if x has no parent).  You can assume that all elements of the array Visited[] are false, and all elements of the array Parent[]  are -1 when the function is first called.  
  3. public static void PrintPath(int Parent[], int endvertex)
     
    Prints out the path from the root of the tree to endvertex, all on one line, followed by an end-of-line.  If there is no path from the root of the tree to the end vertex (or if the root vertex is passed in), just print out the end vertex, followed by a end-of-line.  Recursion is your friend here.  You may need to use a helper function to get the
    end-of-line printed out correctly.
You are provided with the following files:
All you need to do is download the above three files, and then fill in the bodies of BFS, DFS, and PrintPath in Graphtest.java (as well as adding any helper functions that you might need)
What to turn in: