ALGORITHMS EXAMINATION Department of Computer Science New York University December 17, 2007

Similar documents
CS521 \ Notes for the Final Exam

CMPSCI 311: Introduction to Algorithms Practice Final Exam

8.1 Polynomial-Time Reductions

Final Exam May 8, 2018

Unit 8: Coping with NP-Completeness. Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems. Y.-W.

Solution for Homework set 3

Exercises Computational Complexity

2. CONNECTIVITY Connectivity

Homework 4 Solutions

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

Computability Theory

NP and computational intractability. Kleinberg and Tardos, chapter 8

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

NP-Completeness. Algorithms

NP-Complete Reductions 2

Paths, Flowers and Vertex Cover

The Satisfiability Problem [HMU06,Chp.10b] Satisfiability (SAT) Problem Cook s Theorem: An NP-Complete Problem Restricted SAT: CSAT, k-sat, 3SAT

1 Definition of Reduction

1 Introduction. 1. Prove the problem lies in the class NP. 2. Find an NP-complete problem that reduces to it.

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

NP-Hardness. We start by defining types of problem, and then move on to defining the polynomial-time reductions.

Linear Time Unit Propagation, Horn-SAT and 2-SAT

CMPSCI611: The SUBSET-SUM Problem Lecture 18

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

NP-complete Reductions

Boolean Functions (Formulas) and Propositional Logic

8 NP-complete problem Hard problems: demo

W4231: Analysis of Algorithms

PCP and Hardness of Approximation

CS 512, Spring 2017: Take-Home End-of-Term Examination

FINAL EXAM SOLUTIONS

Chapter 9 Graph Algorithms

Assignment 4 Solutions of graph problems

Example of a Demonstration that a Problem is NP-Complete by reduction from CNF-SAT

CS 125 Section #10 Midterm 2 Review 11/5/14

Chapter 10 Part 1: Reduction

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

Chapter 9 Graph Algorithms

2SAT Andreas Klappenecker

CS 373: Combinatorial Algorithms, Spring 1999

Lecture 14: Lower Bounds for Tree Resolution

arxiv: v2 [cs.cc] 29 Mar 2010

Some Hardness Proofs

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

SAT-CNF Is N P-complete

Chapter 9 Graph Algorithms

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

CSE Qualifying Exam, Spring February 2, 2008

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/27/18

Solutions for the Exam 6 January 2014

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

The Resolution Algorithm

Chapter 8. NP-complete problems

Lecture 9 March 4, 2010

Parallel Computation: Many computations at once, we measure parallel time and amount of hardware. (time measure, hardware measure)

The Encoding Complexity of Network Coding

Exam in Algorithms & Data Structures 3 (1DL481)

Binary Decision Diagrams

P and NP (Millenium problem)

CPSC 536N: Randomized Algorithms Term 2. Lecture 10

Paths, Flowers and Vertex Cover

Steven Skiena. skiena

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

6.006 Final Exam Name 2. Problem 1. True or False [30 points] (10 parts) For each of the following questions, circle either True, False or Unknown.

Subset sum problem and dynamic programming

PACKING DIGRAPHS WITH DIRECTED CLOSED TRAILS

9.1 Cook-Levin Theorem

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

Lecture 8: The Traveling Salesman Problem

Treewidth and graph minors

P and NP CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang

Final Exam Solutions

6.856 Randomized Algorithms

4.1 Review - the DPLL procedure

CS 125 Section #4 RAMs and TMs 9/27/16

Vertex Cover Approximations

CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Decision Problems. Observation: Many polynomial algorithms. Questions: Can we solve all problems in polynomial time? Answer: No, absolutely not.

Lecture 7: Counting classes

CMSC Theory of Algorithms Second Midterm

22 Elementary Graph Algorithms. There are two standard ways to represent a

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Where Can We Draw The Line?

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

P and NP CISC5835, Algorithms for Big Data CIS, Fordham Univ. Instructor: X. Zhang

Lectures 8/9. 1 Overview. 2 Prelude:Routing on the Grid. 3 A couple of networks.

Lecture 2: NP-Completeness

Algorithms Exam TIN093/DIT600

Solving problems on graph algorithms

Prove, where is known to be NP-complete. The following problems are NP-Complete:

Lecture 22 Tuesday, April 10

Introduction to Graph Theory

Notes for Lecture 24

Basic Properties The Definition of Catalan Numbers

Scribe: Virginia Williams, Sam Kim (2016), Mary Wootters (2017) Date: May 22, 2017

Transcription:

ALGORITHMS EXAMINATION Department of Computer Science New York University December 17, 2007 This examination is a three hour exam. All questions carry the same weight. Answer all of the following six questions. Please be aware that to pass this exam you need to provide good answers to several questions; it is not sufficient to obtain partial credit on each question. Please print your name and SID on the front of the envelope only (not on the exam booklets). Please answer each question in a separate booklet, and number each booklet according to the question. Read the questions carefully. Keep your answers legible, and brief but precise. Assume standard results, except where asked to prove them. Good luck! 1

Question 1 Let G = (V, E) be an undirected graph with vertex set V and edge set E. A partition of a graph is a partition of V into two disjoint sets, i.e., V = V V and V V =. An edge is said to be cut by a partition, if one of its endpoint lies in V and the other in V. Show that there always exists a partition that cuts at least E /2 edges (i.e. half of the total number of edges in the graph). Solution. A probabilistic argument runs as follows. Choose a random cut, i.e., for each vertex, assign it to V with probability 1/2. Now calculate the expected number of edges that cross the cut. For each edge, it is easy to calculate that it crosses the cut with probability 1/2, and so by linearity of expectation, the expected number of edges that cross the cut is E /2. It follows that some partition must attain the bound E /2. Go To the Next Page 2

Question 2 Let {x 1, x 2,..., x n } be boolean variables. A literal is either a variable or its negation, i.e. x i or x i. A clause is logical OR of one or more distinct literals. The size of a clause is the number of literals in it. A 2CNF formula φ is a collection of m clauses (possibly with repetition), where each C i is of size at most two. φ = (C 1, C 2,..., C m ), Let MAX-2SAT be the following decision problem: Given a pair (φ, k), where φ is a 2CNF formula with n variables and m clauses, and k is a positive integer such that k m, decide whether there exists an assignment to the n boolean variables that satisfies at least k clauses. Show that MAX-2SAT is NP-complete, by giving a polynomial time reduction from VERTEX COVER. Recall that VERTEX COVER is a problem where, given an undirected graph G = (V, E), with V = n, and given a positive integer l n, one needs to decide whether G has a vertex cover of size at most l. A vertex cover is a subset V V such that for every edge in E, at least one of its endpoints is included in V. Hint: To every vertex in the graph, assign a boolean variable which is intended to be TRUE if and only if the vertex is included in the vertex cover. Add clauses of size two corresponding to the edges, and clauses of size one corresponding to the vertices. The clauses corresponding to edges may need to be repeated a number of times. Solution. Let (G = (V, E), l) be an instance of the VERTEX COVER problem, with V = {1, 2,..., n}, and m = E. Introduce a boolean variable x i corresponding to vertex i. The intention is that x i is TRUE iff vertex i is in the vertex cover. For an edge e = (i, j) E, let C e denote the clause C e := x i x j. Note that C e is satisfied iff either x i or x j is TRUE, i.e. iff e is covered by the intended vertex cover. Let Ce 1, Ce 2,..., Ce 2n be clauses that are copies of (the same) clause C e. Let φ be be the 2SAT formula defined as n φ := {x i } i=1 {Ce 1, Ce 2,..., Ce 2n }. e E 3

Note that φ has a total of n + 2mn clauses. Let k := n + 2mn l. We will show that there exists a vertex cover of size at most l iff there is an assignment to the n boolean variables that satisfies at least k clauses. For the forward direction, let V be a vertex cover of size at most l. Consider the boolean assignment where x i is TRUE iff i V. As observed before, since V is a vertex cover, all the clauses Ce j are satisfied for e E, 1 j 2n. A clause x i is satisfied unless i V and there are at most l such i s. Therefore this assignment satisfies at least (n l) + 2mn clauses. For the reverse direction, assume that there is a boolean assignment that satisfies at least n + 2mn l clauses. First we claim that all the clauses Ce j must be satisfied. This is because otherwise, since these clauses occur as 2n copies of the same clause, at least 2n clauses will be unsatisfied and 2n > n l. Now assume that all the edge clauses are satisfied, which implies that at most l vertex clauses are not satisfied. Let V be the set of vertices i for which x i = TRUE. Clearly V l, and V is a vertex cover since all the edge clauses are satisfied. Go To the Next Page 4

Question 3 Let T = (V, E) be an arbitrary (not necessarily binary) tree of n vertices where each vertex v contains a number v.val. Let the root of T have depth zero, and define Goodness(T ) = v V 2 depth(v) v.val, so that Goodness(T ) is the sum of weighted vertex values where the weighting for v.val is 2 raised to the exponent that is the depth of v in T. Now let A[1..n] be an array of n numbers that could be positive or negative. For any tree T of n vertices, let T (A) assign the values in A[1..n] to V so that v.val is A[j], where v is the jth vertex reached in a preorder traversal of T. That is, T (A) is formed by the code: global A[1..n]; global preid 1; procedure DFS(T ) ; T.val A[preid]; preid preid + 1; for each child v of T do DFS(v) endfor; Of course, there are many trees T of n vertices. Present a recursive dynamic programming formulation that computes the greatest Goodess value for trees with data A. Code is unnecessary as is the use of lookup tables, which would be used to make the solution efficient. Hint: Observe that T can be viewed as a tree U with the same root as T plus a rightmost subtree W that hangs off of that root. So U is the entirety of T, apart from the rightmost subtree of the root. In this case, the elements of W comprise a suffix of A, which is to say that if W has k vertices, then its data elements are the sequence A[n k + 1], A[n k + 2],..., A[n]. Solution. Let Good(i, j) be the greatest goodness among all trees built with the preorder values in A[i..j]. Then { A[i] if i = j; Good(i, j) = max i<k j {Good(i, k 1) + 2Good(k, j)} otherwise. 5

Go To the Next Page 6

Question 4 You are to design an algorithm that determines whether or not the language of a given deterministic finite automaton (DFA) is infinite. The alphabet for the DFA is {0, 1}. If the DFA has n states, it is encoded using three arrays: D 0 [1..n], D 1 [1..n], and F [1..n]. Here, it is assumed that the states are 1,... n, and that state 1 is the start (or initial) state. The arrays D 0 and D 1 encode the transition function: if the machine reads a 0 in state i and moves to state j, then D 0 [i] = j, and if the machine reads a 1 in state i and moves to state k, then D 1 [i] = k. The array F encodes the set of final (or accepting) states: if i is a final state, then F [i] = 1, and otherwise, F [i] = 0. Design an efficient algorithm that determines if the language of bit strings accepted by such a DFA is infinite. It should be as efficient as possible (ignoring constant factors in the running time). Solution. (Sketch) Covert the DFA to a graph, find SCC s, and look for a path from the SCC containing the start state top the SCC containing a finial state which goes through some non-trivial SCC, which consists of either two or more nodes, or a single node with a self loop (DFS/BFS + graph cloning easily takes care of all this). Comment: since this is already pretty easy, I don t tell them to shoot for a O(n) running time. Go To the Next Page 7

Question 5 Let G = (V, E) be directed graphs with edge weights w : E R. For vertices u and v, the distance from u to v, denoted δ(u, v), is the weight of the least-weight path from u to v, if such a path exists. There are two exceptional cases: if there is no path from u to v, then δ(u, v) := + ; if there is a path from u to v that contains a negative-weight cycle, then δ(u, v) :=. Design and analyze an algorithm that takes G and w as input, and computes δ(u, v) for all pairs u, v V. Your algorithm should run in time O( V 3 ). HINT: the standard Floyd-Warshall algorithm assumes that the graph contains no negative-weight cycles; show how to modify this algorithm appropriately. Solution. Number the nodes 1..n. For k = 0..n, define δ k (i, j) to be the distance from i to j via paths with intermediate nodes in {1..k}. Assume w(i, j) := if (i, j) is not an edge. By inspection, we have: and δ 0 (i, i) = min(0, w(i, i)) δ 0 (i, j) = w(i, j) for i j Also, for k = 1..n, we have { } δ k (i, j) = min δ k 1 (i, j), δ k 1 (i, k) + (δ k 1 (k, k)) + δ k 1 (k, j), where x := if x < 0, and x := 0, otherwise; moreover, the following convention applies to addition with : (+ ) + ( ) = +. From this, one can just read off an O(n 3 )-time algorithm. Go To the Next Page 8

Question 6 An addition gate is a boolean gate with 3 input bits and 2 output bits, representing the sum (modulo 2) of the input bits, and the carry bit. An addition circuit is a boolean circuit built out of addition gates, with fan out restricted to one. The circuit may have several input bits and several output bits. You are to prove that when such a circuit is evaluated, the number of carries generated by the addition gates is equal to the number of 1-bits in the input minus the number of 1-bits in the output, regardless of the structure of the circuit. To make the problem more precise, the truth table for an addition gate is as follows, where c is the carry, and s the sum: c s 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 An addition circuit can be viewed as a directed acyclic graph, where each edge (i.e., wire ) is labeled i (an input wire ), c (a carry wire ), or s (a sum wire ), and where vertices (i.e., gates ) are one of three types: Input: no incoming edges, and one outgoing edge labeled i; Addition: three incoming edges, and two outgoing edges, labeled c and s; Output: one incoming edge, and no outgoing edges. The incoming edge of an output gate is called an output wire (but it is also either an input, carry, or sum wire). If we assign bit values to each input wire, then since the graph is acyclic, we may evaluate the circuit, assigning to each wire a bit value, using the above truth table to determine the values assigned to the outgoing carry and sum wires on each addition gate, computed as a function of the values assigned to the incoming wires. If I be the number of 1-bits assigned to input wires, C is the number of 1-bits assigned to carry wires, and O is the number of 1-bits assigned to output wires, then the statement you are asked to prove is: C = I O. See the following page for an example. 9

Example. In the following circuit, we have I = 3, C = 2, and O = 1. 1 0 1 1 0 1 c s c 1 s 0 0 Solution. Place $1.00 on each input bit that is a one, and no money on each zero. Then there are enough dollars so that the dollars can be moved to the outputs with each one covered by a dollar, each zero covered by nothing, and an extra dollar left over whenever a carry is generated. So the number of leftover dollars, which is the difference between the number of ones in the inputs and the number of ones in the answer is exactly the number of carries generated by the adder circuits. 10