COSC413 Examination on Advanced Algorithms 31 May 2007, 3:00-5:00 pm Lecturer: Prof. T. Takaoka Open book, calculators are allowed All questions receive 20 points each (1) Transform the following satisfiablity problem into the corresponding colorability problem, and discuss the corresponding solutions. F = (x1‘+ x2 + x3’)(x1 + x2’+x3)(x1‘+x2+ x3) Note. x’ is the negation of x, multiplication is ‘and’, and addition is ‘or’. Do not seek possibility of attaching the special color to the outermost vertices of the graph. (2) Transform the above satisfiability problem into the corresponding clique problem, and discuss the corresponding solutions. Note. To discuss corresponding solutions, list up all truth value assignments that satisfy F, and obtain the corresponding solutions in the transformed problems. (3) Let a difference equation be defined by x(0) = 0, x(1) = 1 x(n+2) = 2x(n+1) + 3x(n) (n=0, 1, ...) (3.1) Obtain the analytical solution for this equation. (3.2) Transform the equation into a vector-matrix form as follows: x(n+1) = 2x(n) + 3x(n-1) This is transformed to the following. (x(1), x(0)) = (1, 0) (x(n+1), x(n)) = (x(n), x(n-1)) a11 a12 a21 a22 = (x(n), x(n-1)) A Obtain the matrix A. Then we have (x(n+1), x(n)) = (x(1), x(0)) An. Obtain x(6) by using the analytical solution, repeated use of the equation (3.2) five times and the repeated quaring of the form (A2A)2 , and confirm that you have the same results. Note. Any linear recurrence of the above type is O(logn) computable. (4) The Euclidean algorithm for greatest common divisors is given as follows: For a > b > 0 such that a = bq + r, let a = r(0), b = r(1), q = q(1) and r = r(2). We repeat division as follows: a = b*q(1) + r(2), 0 <= r(2) < b b = r(2)q(2) + r(3), 0 <= r(3) < r(2) ... r(i-1) = r(i)q(i) + r(i+1), 0 <= r(i+1) < r(i) ... r(n-1) = r(n)q(n) + r(n+1), r(n+1) = 0 gcd(a, b) = r(n) (4.1) Trace this algorithm with a = 112 and b = 63. (4.2) Define sequences c and d by c(0) = 0, c(1) = 1, c(i) = c(i-2) - q(i-1)c(i-1) d(0) = 1, d(1) = 0, d(i) = d(i-2) - q(i-1)d(i-1). Then we have a*d(i) + b*c(i) = r(i) for i=0, ..., n. By tracing sequences c and d, compute 9-1 mod 16 in the range of {1, ..., 15} and 16-1 mod 9 in the range of {1, ..., 8}. (4.3) Prove that (m-1)-1 = m-1 in Zm* for any m>1. Confirm this with 15-1 mod 16. (5) A triangulation of a convex polygon is to divide it into triangles. All triangulations of a pentagon is listed below. 1 5 2 3 4 There are N=C(2n, n)/(n+1) such triangulations for a (n+2)-polygon, where C(n, k) is the binomial coefficient of k out of n, that is, C(n, k)=n!/(n!(n-k)!). For a pentagon, n=3, and N=6!/(3!3!)=5. N is called the Catalan number. Let us give a cost c[i][j] to each edge (i, j) for i<j. The cost of a triangulation is to minimize the total cost of edges used in the triangulation. The optimal triangulation is a triangulation with the minimum cost. We solve this problem by dynamic programming. Now let us give costs c for the above pentagon, and working for the optimal solution f is given as follows: c 1 2 3 4 5 f 1 2 3 4 5 -----------------------------------------------------1 | 0 1 4 6 1 1 | 0 1 6 13 13 f[1][5] =min{f[1][2]+f[2][5] 2 | 0 1 3 5 2 | 0 1 7 11 f[1][3]+f[3][5] 3 | 0 1 7 3 | 0 1 9 f[1][4]+f[4][5]} 4 | 0 1 4 | 0 1 +1 5 | 0 5 | 0 min{12, 15, 14}+1 --------------------------------------------------------Let f[i][j] be the optimal solution for the sub-polygon made by vertices (i, i+1, …, j). We obtain f[i][j] from small value (=2) of j-i until we reach f[1][n] by the following recurrence formula. Let f[i][i]=0 for all i. f[i][j]= min {f[i][k]+f[k][j] + c[i][j]} for all i < j i<k<j (5.1) List up all triangulations for a hexagon (there are six vertices), and confirm the number by the Catalan number. The solution for the pentagon and the general situation is depicted below. 1 1 4 1 1 6 5 5 3 3 1 7 1 1 1 Optimal solution Initial data 1 n j i i+1 k+1 k We assume the optimal solutions for (i, i+1, …, k) and (k, k+1, …, j) are known for all k (i<k<j). Then we check all such k between i and j for the optimal solution for polygon (i, i+1, …, j). (5.2) Trace the algorithm for a hexagon whose costs are given by c 1 2 3 4 5 6 -------------------------------1 | 0 1 4 6 7 1 2 | 0 1 3 5 4 3 | 0 1 7 2 4 | 0 1 3 5 | 0 1 6 | 0 --------------------------------Show the optimal triangulation in picture. (5.3) Compare this solution with the exhaustive method by all triangulations, and discuss which is more efficient. Note. Approximate value of n! is given by Stirling’s formula n! = nne-n/(2πn)1/2