Homework 4 -- Don't forget to put each problem on its own page!
Grading Session is the evening of March 19 at 7:00pm.
x1 + 2 x2 + x3 <= 2
-x1 <= 1
2x1 - 3 x3 <= 0
- x2 <= 0
So here the number of variables n=3, the number of constraints m=4. Then
the matrix A is and the vector b is
1 2 1 2
-1 0 0 1
2 0 -3 0
0 -1 0 0
Notice that requiring that Ax <= b is exactly saying that
you want a value for x1, x2, x3 so that the given 4 constraints are
satisfied. The decision problem is then, "Is a vector x of n bits such that
Ax <= b?" That is, if the bits in the n-vector x give the
values for x1, x2 and x3, is there a solution wheren
the above 4 inequalities are satisfied.Note that in the 3-CNF-SAT problem you are asked to find an assignment to the variables so that at least one literal in each of the clauses is true. In the 0-1 Integer Programming problem you are asked to find an assignment to the variables so that each of the constraints is satisifed.
Homework 3 -- Don't forget to put each problem on its own page!
(Problems 7 and 8 can be combined).
2. Then briefly argue that there exists a polynomial time algorithm A that takes as inputs the graph G and a certificate C such that.
a) If G is 3-colorable then there is some certificate C, such that algorithm A on inputs G and C, A will output "yes", G is 3-colorable.
b) If G is not 3-colorable then for any certificate C, algorithm A on inputs G and C will output "no", G is not 3-colorable.
Notice that you are only asked to prove that Graph-3-colorability is in NP (not that it is NP-complete).
0 if i = 0
c[i,j] = infinity if i > j
min{c[i-1,j-1]+|hi-sj|,c[i,j-1]} otherwise
where c[i,j] is the optimal solution for pairing skiers h1,h2, ...,hi
with skis s1,s2,...,sj for 0 <= i <= n and 0 <= j <= m.
You MUST your output for this data along with your code.
To make it easier for you to test your program, here is the input and output from what was used for the exam.
#include "stdinc.h"
main(){
int **A;
int n, m;
cin >> n;
cin >> m;
A = new int*[n];
for (int i=0; i<=n-1; i++)
A[i] = new int[m];
// You can now access an entry with A[i][j] as shown below
// Note that the above is all you need to do to allocate
// the array. What is below is just to demonstrate the use.
// You shouldn't do anything like the below for your homework
for (i=0; i<=n-1; i++)
for (int j=0; j<=m-1; j++)
A[i][j] = i+j;
cout << "Here is the matrix " << endl;
for (i=0; i<=n-1; i++){
for (int j=0; j<=m-1; j++)
cout << A[i][j] << " ";
cout << endl;
}
}
public class Test {
public static void main(String args[]){
int n = Terminal.readInt();
int m = Terminal.readInt();
int A[][] = new int[n][m];
// You can now access an entry with A[i][j] as shown below.
// Note that the above is all you need to do to allocate
// the array. What is below is just to demonstrate the use.
// You shouldn't do anything like the below for your homework
for (int i=0; i<=n-1; i++)
for (int j=0; j<=m-1; j++)
A[i][j] = i+j;
Terminal.println("Here is the matrix");
for (int i=0; i<=n-1; i++){
for (int j=0; j<=m-1; j++)
Terminal.print(A[i][j] + " ");
Terminal.println("");
}
}
}
ctatg ttaagc
For example in the matrix multiply example we had: For
1 <= i <= j <= n, m[i,j]held the number of scalar multiplies for the optimal way to parenthesize
A_i .... A_j
As one more example for the LCS problem the subproblem was to find the LCS for the first i chars of X and the first j chars of Y. We used c[i,j] for the length of the LCS between the first i chars of X and the first j chars of Y.
This step is VERY important for your solution to be easily read and understood.
You can do this, as we've done in class by just giving a recursive definition for the solution for each subproblem in terms of the solutions to smaller subproblems or if you prefer to express it has a recursive procedure that is also fine.
Generally this involves the following steps (which can be combined in your write-up):
This step can be very brief
Along with stated the time complexity be sure to briefly explain your answer.
Homework 1
Return to the CS 441/539 Home Page