Assignment 5

Due Tuesday, July 26 at 9:00 AM

Be sure you are acquainted with my collaboration policy and my late policy, both found on the main course webpage.


Clarification: For question 2, use a min-heap.


  1. Explain the differences between linear probing, quadratic probing, and chaining as methods of collision handling in a hash table.

  2. Starting with an empty heap, perform the following operations, showing the heap (as an array) at each step:

  3. Imagine that you have a PriorityQueue class, implemented as a heap, that stores ints and has the following methods: void insert(int n), int removeMin(), and boolean isEmpty(). Implement a method called "heapSort" that takes an array of integers and returns an array containing the same values in sorted order (from least to greatest). This should be done using the PriorityQueue class and should have a run-time of O(n*log(n)). Explain why it has this run-time. The method signature will look like this:
    public int[] heapSort(int[] arr) {...}
    (Note: if you want to check your algorithm, you are free to implement the PriorityQueue class. Alternatively, you can test it out using Java's built in PriorityQueue, though the method names will differ.)

  4. This question deals with testing for connection within a graph.
    1. In an undirected graph, a graph is connected if for every pair of nodes J and K, there exists a path from J to K. It is simple enough to test for this by performing a depth-first search starting at some arbitrary node and keeping track of the number of nodes it touches. If it touches the total number of nodes in the graph, the graph is connected; else, it is not. Could this be done with a breadth-first search? If so, what would need to be changed? If not, why not?
    2. In a directed graph, things become a little more complicated as we will have multiple types of connectivity. A graph is said to be weakly connected if replacing all of its directed edges with undirected edges produces a connected undirected graph. Describe an algorithm to test for weak connectivity and analyze its run-time.
    3. A directed graph is said to be strongly connected if for every pair of nodes J and K, there exists a path from J to K and a path from K to J. Describe an algorithm to test for strong connectivity and analyze its run-time.

Turning in your work

To hand in your program, copy your answers (stored in a text file) into the following directory:

/p/course/cs367-ealexand/handin/login-name/H5

Use your actual CS login name (not your UW NetID!) in place of login-name.

You should write this assignment up by yourself. If you share ideas with anyone, be sure to cite them.