CS 432 - Fall 2007

Jim Cohoon

Home | Documents | Homework | SlidesPeopleUploads | Code | Email Log  | Grades


Solutions are available .

 

Assignment 10 Due in the CS office by 16:00 December 5. You may work in groups of up to three people. The group hands in a single homework. Also, indicate the relative percentages of each individual's contributions (might be used to supplement class participation).

Reductions -- descriptions of the problems are available in the slides
  • Show how the Hamiltonian cycle problem reduces to the traveling salesperson problem.
  • Show how the partitioning problem reduces to the knapsack problem.
  • Show how the partitioning problem reduces to sum of subsets problem.
  • Show how the sum of subsets problem reduces to the partitioning problem.
  • Show how the generic CNF satisfiability problem reduces to CNF satisfiability-3 problem.

The standard practice for demonstrating a reduction is

  • Converts an arbitrary instance IA of  problem A to an instance IB of problem B such that
    • Solution for IB implies solution for IA
    • No solution for IB implies no solution for IA
  • Show from solution IB for B we know the solution for IA of A

     

Assignment 9 Due: 15:00 November 30 in the CS Office
  • Attend the time management lecture by Randy Pausch. The talk will be in Old Cabel Hall on November 27 at 3:00PM.  A one-page, single-spaced printed copy of a paper discussing the talk and its problem-solving time-management strategies.
Assignment 8 Due: 15:00 November 30 (electronic submission)
  • Supplement TSP.java to produce a member method interchange() and a method edgesCross(). There is also a GUI for testing.
    • Method interchange() takes two int parameters u and v. The parameters are the indices into the tour (i.e. tour[u] and tour[v] are city indices. Let succ(i) equal 1 + i mod n, where n is the number of vertices.
      • If ( v < u )
        • return interchange(v, u)
      • If v equals either u or succ(u) or if u = succ(v)
        • The method should simply return 0.
      • Otherwise. the method should modify the current tour in the following manner
        • The tour should not represent the inclusion of edges from vertex tour[u] to vertex tour[succ(u)] and from vertex tour[v] to vertex tour[succ(v)].
        • The tour should instead represent the inclusion of edges from vertex tour[u] to the vertex tour[v] and from vertex tour[succ(u)] to the vertex tour[succ(v)].
        • In addition, the subtour previously proceeding from vertex tour[succ(u)] to vertex tour[v)], should now proceed from tour[v] to tour[succ(u)].
        • The method should return the difference of the length of the old tour minus the length of the new tour.
    • Method edgesCross() takes for int parameters a, b, c and d. The method returns whether the edge connecting cities a and b crosses over the edge connecting cities c and d.
  • Class TSP provides the following support for your efforts.
    • int succ(int  i)
      • returns the i + 1 mod n, where n is the number of cities
    • distance(int i, int j)
      • returns the distance between cities i and j
    • Point[] city
      • city[i].x is the x-coordinate of the location of city i
      • city[i].y is the x-coordinate of the location of city i
      • city.length is the number of cities
Assignment 7 Due: November 20 in class
  • View the last lecture by Randy Pausch. The talk is available through streaming. A one-page, single-spaced printed copy of a paper discussing the talk and its motivational power.
Assignment 6 Due: November 12 by 15:00 in the CS Office
  • Two-page printed copy of a paper discussing simulated annealing. You may use the original paper as your source.
Assignment 5
Due: Wednesday October 24 ( Electronically )
  • CS 101 assignment 4. Name your solution EditDistance.java .

    Please name your problem solving method solve(). Method solve() should either be nonrecursive or employ memoization to ensure that the algorithm is quadratic.

    Method solve() should take two String parameters. The supplied template calls the solve() parameters s1 and s2. Method solve() should return a Solution. The supplied class Solution has a single constructor taking five parameters. They are

    • The strings s1 and s2 to be edit distanced.
    • A two dimensional int array optimal with dimensions s1.length+1 and s2.length+1. The array stores the values of the optimal edits
    • Strings t1 and t2 representing the edit instructions for s1 and s2. Each character in an instruction supplies string the next character in the string to be edit distanced or a hyphen to ignore the next character is to be skipped.
    • A String penalty whose characters are all amongst '0' or '1' or '2'. The ith penalty character gives the penalty associated with the ith position in edit instructions t1 and t2.

    Class Solution also provides a toString() method that may be helpful in debugging. For example,
           System.out.println( solve("AACAGTTACC","TAAGGTCA");
    produces

     7  8 10 12 13 15 16 18 20 
     6  6  8 10 11 13 14 16 18 
     6  5  6  8  9 11 12 14 16 
     7  5  4  6  7  9 11 12 14 
     9  7  5  4  5  7  9 10 12 
     8  8  6  4  4  5  7  8 10 
     9  8  7  5  3  3  5  6  8 
    11  9  7  6  4  2  3  4  6 
    13 11  9  7  5  3  1  3  4 
    14 12 10  8  6  4  2  1  2 
    16 14 12 10  8  6  4  2  0 
    
    AACAGTTACC
    TAAGGTCA
    
    AACAGTTACC
    TA-AGGT-CA
    1020010201

    Class Solution also provides a method validate() that makes a reasonable effort to determine whether your solution is feasible (it does not check for optimality).

  • Text book problem 2.b on pages 313-314 . Name your solution WorkPlan.java .

    Please name your problem solving method solve(). Method solve() should either be nonrecursive or employ memoization to ensure that the algorithm is linear.

    Method solve() should take two int[] parameters. The supplied template calls the solve() parameters low and high. Method solve() should return a Solution. The supplied class Solution has a single constructor taking four parameters. They are

    • The int[] arrays low and high to be used to determine the maximum possible wages.
    • At int[] array week with dimension low.length. The array stores the values of the optimal accumulated wage total for each week of work; that is, week[i] is the maximum amount of wages it is possible earn through week i (which is not necessarily the amount through week i for the overall optimal schedule).
    • String schedule representing the instructions to achieve the maximum accumulated wages for the last week.
    • The instruction for a given week is L, H, or -. indicating whether to take the low stress wage, the high stress wage, or not to work.

    Class Solution also provides a toString() method that may be helpful in debugging. For example,
           System.out.println( solve("AACAGTTACC","TAAGGTCA");
    produces

     10   1  10  10   0  10   1  10  10 
      5  50   5   1   0   5  50   5   1 
    
      -   H   L   L   L   -   H   L   L 
    
     10  50  60  70  70  80 120 130 140 
    
    true
    

    Class Solution also provides a method validate() that makes a reasonable effort to determine whether your solution is feasible (it does not check for optimality).

Assignment 4 Due: Tuesday October 9 by 10:00AM. Implement a linear time algorithm for the selection problem. The code is solely to be a product of your own work. You may discuss individual aspects with others but code is not to be shared to or from anyone or anywhere. Homework is to be submitted electronically. Further information on how to submit will be given later.
  • Create a Java class with the name Select.java . The class must have a static method select() taking four parameters. The first parameter is an int array a. The second and third parameters are int values left and right indicating the indices specifying the subarry of interest within array a. The fourth parameter is an integer k giving the value of interest.
  • The select algorithm discussed in class is available
Assignment 3

Due: Friday September 21 by 11:00 (CS Office Olsson Hall)
  • Do the problem you did not do from the previous assignment.
Assignment 2 Due: Friday September 14 by 11:00 AM (CS Office Olsson Hall)
  • Text book: do either Page 189: exercise 3 or Page 190: exercise 5. For those still without the textbook, the pages in question are available.
    • For exercise 3, you do not have to make your proof/convincing argument based on the scheduling proof from the text. Although an analogous proof/convincing argument does work nicely. You could also try my favorite proof technique -- proof by contradiction,
    • For exercise 5, view the houses as a line graph where the edge weights are the lengths between houses; for example,

               H-------H--H-----H-----H---H

      You need to come with an algorithm that places the least number of cell towers on the line so that every house is within 4 miles of a tower. Your answer needs to supply the following: a correct algorithm with a description of how it works gets, along with a proof/convincing argument that the algorithm is correct. In my opinion the argument could be easily supplied in a single paragraph.
  • A node cover U of G = (V, E) is a subset of V such that for every edge (a, b) in E, at least one of a and b is in U. A minimum node cover for a graph is the cover with the fewest vertices. Show that a greedy algorithm that considers vertices in order of degree (high to low) does not necessarily produce a minimum node cover.
    • A graph with nine vertices makes a straightforward example.
    • A graph with five vertices also works, but some of you will not like it as an answer.
    • When I am asked to come up with a counter example for a graph problem, I first consider line and circle graphs and then trees as possibilities. I try to make some node the one that the greedy algorithm selects and then attach edges that makes that choice bad.
    • If it helps your visualization, here is an implementation of the bad greedy strategy.
      • U = empty set
      • While E is not the empty set do
        • v = a vertex with maximum degree in E
        • U = U + v
        • E = E - { (a, b) | (a, b) is in E and a equals v or b equals v }
      • End
Assignment 1
Due: Friday September 7 by 11:00AM (CS Office Olsson Hall)
  • Page 67: exercises 1.a, 1.b, 2,a, 2,e
  • Page 68: 6.b
  • Show that a polynomial p(n) of degree k is not O( nk-1 )
     
  • Helpful hints
    • When asked to consider a function f(n) when the input size doubles the value of interest is f(2n)
    • The sum of 1 + 2 +3 ... + j = j(j+1)/2
    • The sum of i + i+1 + i+2 ... j = j(j+1)/2 - i(i-1)/2
    • To show a function f(n) is not O(g(n)) appeal to the definition given in class and try showing that in the limit the ratio f(n)/g(n) =
Exercise 1 Fruit question -- solution due at the start of class Thursday August 30
  • There are three labeled baskets whose inner contents you cannot see: a basket with just apples, a basket with just oranges, and a basket with oranges and apples. Suppose all of the basket labels are wrong? How you figure out which basket is which by taking only one piece of fruit?
  Coin changing for ak down to a0

Minimum node cover

Unique edge weights mean unique MST

#3

#5