CS 4102, Algorithms
Problem Set #5, Spring 2010

Updated: April 2, 2010, 10am -- fixed minor typos identified in class yesterday.

Homework 5 is a "long" homework, worth the same as HWs 1 and 2.   Like HWs 1 and 2, you can work alone or in groups of two -- see rules below (same as for HW1 and 2, different than HW 3).


To turn in:

Turn in solutions to these problems.  (Below they're marked with this image: Submit-Button)

Important: Put the answer to each question on a separate sheet of paper (or one problem on front and another on the back). This is to make grading easier for us.

Collaboration Rules for This Assignment:

  1. There are many problems here. There are six to submit.  For the ones that are not required to be submitted, you can collaborate or discuss in any way with as many people as you wish.
  2. For the required problems that you submit:
    1. You may submit your work on your own or with up to two partners.  If you work with a partner, you must pledge that all partners did approximately equal amounts of work on the required problems.
    2. If you work alone, you can discuss how to solve the problems with one other group or one other single person.  List the names of these people on your submission.
    3. If you don't understand the question or what it is asking, you can get clarification from other students only if this does not involve saying how the problem might be solved in any way.  If in doubt, don't discuss and see the TA or the instructor.
  3. Fill out the cover sheet on the website and submit it with your homework.

P1) Submit-Button Background: The exhaustive search algorithm given in the slides will find all possible unique paths from the start node in a graph G, and can easily be modified to find Hamilton cycles (a simple cycle that visits each node). However, you know the exhaustive search tree this approach explores is very large, and you decide to use a pruning method to avoid making a choice (and thus exploring a subtree that could not lead to a valid result. Pruning is a technique where you do some extra computation before visiting a new node; this computation might tell you not to visit that node, even if it hasn't been visited before. Thus the goal of computation is to determine, if possible, in advance if a path will lead to a dead-end.

Here's an example of pruning. Sometimes the path found so far may divide the set of unvisited nodes into two sets that are "cut off" from each other. For example, in the graph below, if the exhaustive search algorithm starts off choosing the path A-C-E then we can tell by looking that this will not lead to a solution, i.e. there cannot be a Hamilton Cycle that contains A-C-E. See why? This path has divided the graph into two parts: no path can connect B with any node in {D, F} without re-visiting a node that's already been visited.

If we implement this pruning strategy, the change in the code for exhaustive search might look like this:

     if (!visit[v]&& !cutInTwo(adj,visit) )
          exh_search_recurs(adj,v)

Question (3 parts):
First, Describe clearly a strategy for the cutInTwo() function. You can answer this by writing a few sentences describing an approach that solves this problem.
Second, give an upper-bound on the time-complexity for one call to cutInTwo().
Third, discuss in a few sentences whether or not you think it would be cost effective to make this change if you were using this exhaustive search strategy to find all Hamilton cycles found in large, moderately dense graphs.



Greedy Algorithm Problems G0a and G0b: Submit-Button

Develop a greedy algorithm for either one of these problems:
(a) Vertex cover problem -- see problem 7.8 on page 320 in the book
(b) Graph coloring problem, as follows:
A valid coloring of a graph is an assignment of a color (represented by an int value: 1, 2, ...) to each vertex such that no pair of adjacent vertices have the same color. An obvious way to give a graph a valid coloring is to assign each vertex an unique color, but often we want a valid coloring that uses the smallest number of colors. This is the optimization problem version of graph coloring, and this is the one you need to develop a greedy algorithmn for.
Thus the input is a graph G, and the output is an array or dictionary color[] where color[i] is the color assigned to the ith vertex. The answered stored in the color[] array should try to use the smallest number of colors possible.

Note on both of these: Using the greedy approach will almost certainly not produce an optimal solution.
Also to do:  Give me an input to your problem that causes your algorithm to not produce an optimal solution.  (Worth 10% of this problem.)



More Graph Problems:

For the following problems, this the example graph to use:

graph

G1) Carry out Kruskal's MST algorithm on the above graph. List edges in the final spanning tree in the order they were selected, and give the total weight of the tree.

G2) Submit-Button Carry out Prim's MST algorithm on the above graph. List the edges in the order they were selected. Also, when a candidate edge that's stored in the priority queue is replaced with a better candidate edge, list the replaced edge and what replaces it.

G3) Submit-Button Carry out Dijkstra's shortest path algorithm on the above graph. List the edges in the order they were selected. Also, when a candidate edge that's stored in the priority queue is replaced with a better candidate edge, list the replaced edge and what replaces it.

G4) In Prim's MST algorithm, give a list of what the priority queue operations are, what they do, when they occur.

G5) For each of the above priority queue operations, how often can they occur in the worst-case for some graph G?


Greedy Algorithms:

G6) State the greedy selection rule (aka the selection function) for these algorithms:

  1. The fractional knapsack algorithm that produces an optimal solution.
  2. The change-making algorithm.
  3. Kruskal's MST algorithm
  4. Prim's MST algorithm
  5. Dijkstra's shortest path algorithm.

G7) What in Prim's MST algorithm prevents the algorithm from choosing an infeasible solution?