University of Washington March 21, 2013 Department of Computer Science and Engineering CSEP 521, Winter Exam Solution, Monday, March 18, 2013

Similar documents
VIII. NP-completeness

CSCI3390-Lecture 17: A sampler of NP-complete problems

NP and Computational Intractability

CSE 421 Introduction to Algorithms Final Exam Winter 2005

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

Limits to Approximability: When Algorithms Won't Help You. Note: Contents of today s lecture won t be on the exam

NP-Completeness. Until now we have been designing algorithms for specific problems

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

CS 170, Fall 1997 Second Midterm Professor Papadimitriou

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

1. Introduction Recap

Algorithms, Lecture 3 on NP : Nondeterminis7c Polynomial Time

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2013

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Exam EDAF May 2011, , Vic1. Thore Husfeldt

NP-Complete Problems. More reductions

NP Complete Problems. COMP 215 Lecture 20

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Complexity, P and NP

CS/COE

HOMEWORK #2 - MATH 3260

8.5 Sequencing Problems

Combinatorial Optimization

CSCI 1590 Intro to Computational Complexity

Design and Analysis of Algorithms April 16, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 2

Data Structures and Algorithms (CSCI 340)

Data Structures in Java

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Today: NP-Completeness (con t.)

Graph Theory and Optimization Computational Complexity (in brief)

CSI 4105 MIDTERM SOLUTION

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Polynomial-time reductions. We have seen several reductions:

Limitations of Algorithm Power

NP-Completeness. NP-Completeness 1

Graduate Algorithms CS F-21 NP & Approximation Algorithms

Design and Analysis of Algorithms May 12, 2011 Massachusetts Institute of Technology. Practice Final Exam. Problem Title Points Parts Grade Initials

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

Design and Analysis of Algorithms

Mathematical Thinking Exam 2 20 November 2017

ECS122A Handout on NP-Completeness March 12, 2018

NP-completeness. Chapter 34. Sergey Bereg

Algorithm Design and Analysis

Lecture 4: NP and computational intractability

Introduction to Complexity Theory

Lecture 2: Divide and conquer and Dynamic programming

CS 170 Algorithms Spring 2009 David Wagner Final

CS173 Lecture B, September 10, 2015

Polynomial-time Reductions

SAT, Coloring, Hamiltonian Cycle, TSP

Notes for Lecture 21

July 18, Approximation Algorithms (Travelling Salesman Problem)

Data Structures and Algorithms

Tractable & Intractable Problems

Chapter 34: NP-Completeness

Computational Intractability 2010/4/15. Lecture 2

Algorithms Design & Analysis. Approximation Algorithm

CS1800 Discrete Structures Spring 2018 February CS1800 Discrete Structures Midterm Version A

Classes of Problems. CS 461, Lecture 23. NP-Hard. Today s Outline. We can characterize many problems into three classes:

Polynomial-Time Reductions

Design and Analysis of Algorithms

Algorithm Design and Analysis

Midterm 1. Your Exam Room: Name of Person Sitting on Your Left: Name of Person Sitting on Your Right: Name of Person Sitting in Front of You:

NP-Complete Reductions 2

NAME: Be clear and concise. You may use the number of points assigned toeach problem as a rough

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Automata Theory CS Complexity Theory I: Polynomial Time

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

Hamiltonian Graphs Graphs

CSEP 521 Applied Algorithms. Richard Anderson Winter 2013 Lecture 1

Algorithm Design Strategies V

Exam EDAF August Thore Husfeldt

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005

University of New Mexico Department of Computer Science. Final Examination. CS 362 Data Structures and Algorithms Spring, 2007

Correctness of Dijkstra s algorithm

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

Unit 1A: Computational Complexity

Computational Complexity

Introduction to Computational Complexity

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness

CMSC 441: Algorithms. NP Completeness

1 Reductions and Expressiveness

COMP Analysis of Algorithms & Data Structures

Computational complexity theory

CSCI3390-Second Test with Solutions

Lecture 15 - NP Completeness 1

Practice Final Solutions. 1. Consider the following algorithm. Assume that n 1. line code 1 alg(n) { 2 j = 0 3 if (n = 0) { 4 return j

CSCI3390-Lecture 18: Why is the P =?NP Problem Such a Big Deal?

Nondeterministic Polynomial Time

6 Euler Circuits and Hamiltonian Cycles

Algorithms: COMP3121/3821/9101/9801

Transcription:

University of Washington March 21, 2013 Department of Computer Science and Engineering CSEP 521, Winter 2013 Exam Solution, Monday, March 18, 2013 Instructions: NAME: Closed book, closed notes, no calculators Time limit: Two hours Answer the problems on the exam paper. If you need extra space use the back of a page Problems are not of equal difficulty, if you get stuck on a problem, move on. 1 /15 2 /15 3 /10 4 /15 5 /15 6 /15 7 /15 8 /10 Total /110

Problem 1 (15 points) Short Answer: a) How does the run time of finding a minimum cut compare with the run time for finding a maximum flow? To find a minimum cut, we first find the maximum flow, and then find the set of reachable vertices in the residual graph. This last step, can be done by a basic search algorithm in O(n + m) time. Thus, if network flow can be solved in time f(n, m), then the min-cut can be found in time f(n, m) + O(n + m) time. Since the time to compute a flow is much larger than the other step, it is fair to say they can be computed in roughly the same time. b) If you know problem X is NP-complete, and you want to show that problem Y is NP-complete, do you reduce X to Y, or reduce Y to X. Justify your answer. You reduce from X to Y. To show that Y is NP-complete, you want to show that it is harder than another NP-complete problem. c) Yes, no, or maybe: There is a polynomial time algorithm for determining if an undirected graph has a hamiltonian circuit? Justify your answer. Maybe. Hamiltonian Circuit is NP-Complete. However, since we don t know if NP is different from P, the answer is maybe. If there were an polynomial time algorithm for Hamiltonian Circuit, then P=NP. Problem 2 (15 points) Recurrences: Give solutions to the following recurrences. Justify your answers. a) T (n) = { 2T ( n 2 ) + n3 if n > 1 1 if n = 1 O(n 3 ). The recurrence has a decreasing amount of work per level. The amount of work at the top level is n 3. b) T (n) = { 4T ( n 2 ) + n2 if n > 1 1 if n = 1

O(n 2 log n). The work remains the same on each level. The work per level is n 2 and there are log 4 n = 1 2 log 2 n levels. c) T (n) = { 3T ( n 2 ) + n if n > 1 1 if n = 1 O(n log 2 3 ). The recurrence has an increasing amount of work per level, so the work is dominated by the last level. The work on the bottom level is 3 log 2 n = 2 log 2 3 log 2 n = n log 2 3. Problem 3 (10 points) Residual Graph: Consider the following flow graph G, with an assigned flow f. The pair x/y indicates that the edge is carrying a flow x and has capacity y. a 4/9 4/9 2/9 6/9 b 4/8 s 7/14 2/4 c 5/10 d 6/15 e 9/12 t 2/10 f a) Draw the residual graph G f for the flow f.

a d s b e t c f We apply the standard contruction for the residual graph. If there is a flow of f and capaicty c on the edge (u, v), we create an edge of capacity c f from u to v, and an edge of capacity f from v to u. b) Show how the Ford-Fulkerson algorithm can find a maximum flow. List the paths that you use to augment the flow. There are muliple ways of doing this. One set of augmenting paths: 2 : s, c, f, t 3 : s, c, e, t 2 : s, c, e, b, d, t 3 : s, b, d, t 4 : s, a, d, t Problem 4 (15 points) How can you?: Give short answers to the following. You do not need to discuss runtime. How can you: a) Find a maximum weight spanning tree using an algorithm which computes a minimum weight spanning tree. We multiply the weight of every edge by -1, and then compute a minimum spanning tree. b) Determine if there is a path from a vertex s to every other vertex in a directed graph using a network flow algorithm.

We set this up as a flow problem by adding a sink t. We assign a capacity of to each of the original edges in the graph and then add an edge (v, t) of capacity 1 for each vertex v in the graph. If there is a flow of size n from s to t, then every vertex in the graph is reachable. c) Find an optimal travelling salesman tour in a graph which may have negative length edges with an algorithm for the travelling salesman problem that requires all edges have positive length. Add a constant C to each edge to make it positive. Since the TSP tour as length n, this changes the cost of the tour by Cn. If m is the smallest edge in the graph, we can use C = m + 1. Problem 5 (15 points) Product-sum: Given a list of n integers, v 1,..., v n, the product-sum is the largest sum that can be formed by multiplying adjacent elements in the list. Each element can be matched with at most one of its neighbors. For example, given the list 1, 2, 3, 1 the product sum is 8 = 1 + (2 3) + 1, and given the list 2, 2, 1, 3, 2, 1, 2, 2, 1, 2 the product sum is 19 = (2 2) + 1 + (3 2) + 1 + (2 2) + 1 + 2. a) Compute the product-sum of 1, 4, 3, 2, 3, 4, 2. 29 = 1 + (4 3) + 2 + (3 4) + 2. b) Give the optimization formula for computing the product-sum of the first j elements. max{op T [j 1] + v j, OP T [j 2] + v j v j 1 } if j 2 OP T [j] = v 1 if j = 1 0 if j = 0 c) Give a dynamic program for computing the value of the product sum of a list of integers. (You do not need to determine which pairs are multiplies together - just the product.) Prod-Sum(int[ ]v, n) if (n == 0) return 0; int [ ] OP T = new int [n + 1]; OP T [0] = 0; OP T [1] = v[1]; for int j = 2 to n OP T [j] = max(op T [j 1] + v[j], OP T [j 2] + v[j] v[j 1]); return OP T [n];

Problem 6 (15 points) Electoral college: The problem is to determine the set of states with the smallest total population that can provide the votes to win the electoral college. Formally, the problem is: Let p i be the population of state i, and v i the number of electoral votes for state i. All electoral votes of a state go to a single candidate, so the winning candidate is the one who receives at least V electoral votes, where V = ( i v i)/2 + 1. Our goal is to find a set of states S that minimizes the value of i S p i subject to the constraint that i S v i V. a) The dynamic programming solution for this problem involves computing a function OP T where OP T [i, v] gives the minimum populations of a set of states from 1, 2,..., i such that their votes sum to exactly v. Give a recursive definition of OP T and an explanation as to why it is correct. OP T [i, v] = min{op T [i 1, v], OP T [i 1, v v i ] + p i }. The first term corresponds to state i not included in the vote total, and the second term corresponds to the state i included in the vote total. b) What are the base cases for your function OP T. OP T [0, 0] = 0 and OP T [0, v] = for v 1. Grading notes. Part A, 9 Points. Part B, 6 Points. The most common error was to give a base case of 0. Problem 7 (15 points) Currency Conversion: A group of traders are leaving Switzerland, and need to convert their Francs (the local currency) into various international currencies. There are n traders and m currencies. Trader i has T i Francs to convert. The bank has B j Francs worth of currency j. Trader i is willing to trade as much as C ij of his Francs for currency j. (For example, a trader with 1000 Francs might be willing to convert up to 700 of his Francs for USD, up to 500 of his Francs for Japaneses Yen, and up to 500 of his Francs for Euros). Assuming that all traders give their requests to the bank at the same time, describe an algorithm that the bank can use to satisfy the requests (if it can). This is set up as a flow network, with Francs flowing from the source s to the sink t. A row of vertices t 1,..., t n represents the traders, and a row of vertices b 1,..., b m represents the currency held by the bank. The edge (s, t i ) has capacity T i which gives the amount trader i wants to change. The edge (t i, b j ) has capacity C ij giving the maximum number of Francs i wants to trade into currency j. Finally, the edge (b j, t) with capacity B j gives the limit on the amount of currency j that is available. If there is a flow f in the network with f = i T i then all traders are able to convert their currencies. (An alternate solution which reverses the source and sink, and has currency flow to from the banks to traders is also valid.) Problem 8 (10 points) 4SAT: Show that the 4SAT problem is NP-complete by giving a reduction from 3SAT. 4SAT is the satisfiability problem with exactly four literals per clause. You do not need to show that 4SAT is in NP.

The simplest reduction from 3SAT to 4SAT is just to duplicate a literal in each clause, e.g., (x y z) = (x y z z). An alternate approach is to add a variable to each clause that is set to false: (x y z) = (x y z a), where the additional clause (a a a a) forces a to false. (Repeated literals can be avoided by using a group of eight additional clauses to false a to false). Grading notes: Just adding the constant F to a clause was -2, since it is technically not a literal. Points were also lost for confusing and.