FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Similar documents
University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

CSE 421 Introduction to Algorithms Final Exam Winter 2005

CMSC 451: Lecture 7 Greedy Algorithms for Scheduling Tuesday, Sep 19, 2017

Algorithm Design Strategies V

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

ECS122A Handout on NP-Completeness March 12, 2018

VIII. NP-completeness

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

directed weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

CS60007 Algorithm Design and Analysis 2018 Assignment 1

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

Algorithms: Lecture 12. Chalmers University of Technology

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

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Proof methods and greedy algorithms

Greedy Algorithms My T. UF

Data Structures in Java

CMPSCI 611 Advanced Algorithms Midterm Exam Fall 2015

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours

Midterm Exam 2 Solutions

Design and Analysis of Algorithms

IS 709/809: Computational Methods in IS Research Fall Exam Review

Unit 1A: Computational Complexity

Approximation Algorithms for Asymmetric TSP by Decomposing Directed Regular Multigraphs

CS 170 Algorithms Spring 2009 David Wagner Final

CMSC Discrete Mathematics SOLUTIONS TO FIRST MIDTERM EXAM October 18, 2005 posted Nov 2, 2005

Problem set 1. (c) Is the Ford-Fulkerson algorithm guaranteed to produce an acyclic maximum flow?

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Algorithms Exam TIN093 /DIT602

2 GRAPH AND NETWORK OPTIMIZATION. E. Amaldi Introduction to Operations Research Politecnico Milano 1

Maximum Flow Problem (Ford and Fulkerson, 1956)

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Combinatorial Optimization

CS173 Lecture B, November 3, 2015

4. How to prove a problem is NPC

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

Lecture 2: Divide and conquer and Dynamic programming

CSI 4105 MIDTERM SOLUTION

Standard Diraphs the (unique) digraph with no vertices or edges. (modulo n) for every 1 i n A digraph whose underlying graph is a complete graph.

CS 161: Design and Analysis of Algorithms

Homework 1: Algorithm Design Basics

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

8.5 Sequencing Problems

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

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

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

Geometric Steiner Trees

1 Primals and Duals: Zero Sum Games

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

CS675: Convex and Combinatorial Optimization Fall 2016 Combinatorial Problems as Linear and Convex Programs. Instructor: Shaddin Dughmi

1. Introduction Recap

CS 70 Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand Midterm 1 Solutions

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

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Matroids and Greedy Algorithms Date: 10/31/16

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:

Algorithm Design and Analysis

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

Check off these skills when you feel that you have mastered them. Write in your own words the definition of a Hamiltonian circuit.

7.4 DO (uniqueness of minimum-cost spanning tree) Prove: if all edge weights are distinct then the minimum-cost spanning tree is unique.

Part V. Matchings. Matching. 19 Augmenting Paths for Matchings. 18 Bipartite Matching via Flows

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

CS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs. Instructor: Shaddin Dughmi

More on NP and Reductions

Algorithms Design & Analysis. Approximation Algorithm

ACO Comprehensive Exam March 20 and 21, Computability, Complexity and Algorithms

Greedy Algorithms. Kleinberg and Tardos, Chapter 4

CSCE 551 Final Exam, April 28, 2016 Answer Key

Graph Theory and Optimization Computational Complexity (in brief)

Exam EDAF August Thore Husfeldt

Algorithms and Theory of Computation. Lecture 11: Network Flow

1 Some loose ends from last time

CSE 421 Greedy Algorithms / Interval Scheduling

Limitations of Algorithm Power

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

CS325: Analysis of Algorithms, Fall Final Exam

CS 580: Algorithm Design and Analysis

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Polynomial-time Reductions

NP-completeness. Chapter 34. Sergey Bereg

NP and Computational Intractability

Show that the following problems are NP-complete

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

0 1 d 010. h 0111 i g 01100

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

Data Structures and Algorithms

Preliminaries and Complexity Theory

Running Time. Assumption. All capacities are integers between 1 and C.

Exercises NP-completeness

3.4 Relaxations and bounds

Algorithm Design and Analysis (NTU CSIE, Fall 2017) Homework #3. Homework #3. Due Time: 2017/12/14 (Thu.) 17:20 Contact TAs:

Contents Lecture 4. Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Transcription:

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016) The final exam will be on Thursday, May 12, from 8:00 10:00 am, at our regular class location (CSI 2117). It will be closed-book and closed-notes, except that you may bring notes written on (both sides of) a single sheet of letter-size paper, which you will be asked to turn in along with your exam. The following problems may help you prepare for the exam. They are not to be handed in. Solutions are not available, but of course you are welcome to discuss these problems during office hours or on Piazza. Disclaimer: Many of these problems are taken from exams in previous offerings of CMSC 451 when the emphasis of the course may have been different. The exam will not be as long as this set of practice problems, and this selection of problems does not necessarily reflect the difficulty level or distribution of material to be covered on the exam. 1. Short answer questions. For the following questions, explanations are required only when explicitly requested, but can always be given for partial credit. (a) Yes or No: Suppose an algorithm runs in O(n2 (2 log 2 n) ) time. Is this a polynomial-time algorithm? (b) Suppose you are given an undirected graph which has n vertices, and each vertex has exactly six incident edges. As a function of n, what is the total number edges in this graph? (Give an exact answer for full credit, or an asymptotic answer for partial credit.) (c) You are given a digraph G that has edge weights with the values of either +1 or 1. It has no negative-cost cycles. Which of the following can be used to compute shortest paths in G from a single source vertex? (List all that apply): breadth-first search, Dijkstra s algorithm, Bellman-Ford algorithm. (d) You are given a connected, undirected graph G = (V, E) in which each edge has a numeric edge weight, and all edge weights are distinct. Let e 1, e 2, and e 3 be the edges with smallest, second smallest, and third smallest weights among all the edges of G, respectively. Among these three edges, which (if any) must be in the minimum spanning tree (MST) of G, which (if any) might be in the MST, and which (if any) are definitely not in the MST? (e) Explain why Kruskal s MST algorithm made use of a Union-Find data structure. (f) True or False: Suppose that the capacities of the edges of an s-t network are integers that are all integer multiples of 3. Then there exists a maximum flow such that the flow on each edge is also integer multiples of 3. (g) Given a flow network G, let (X, Y ) denote a cut. Let c denote the sum of the edge capacities of all edges (x, y), where x X and y Y. What can be said about the maximum flow in G? i. The value of the maximum flow in G is at most c (but may be smaller) ii. The value of the maximum flow in G is at least c (but may be larger) iii. The value of the maximum flow in G is equal to c. iv. We cannot say anything about the maximum flow, because we failed to consider the capacities of the edges going from Y to X when defining c. 1

(h) True or False: It is possible to determine in polynomial time whether a graph has an independent set of size 100. (i) Technically advanced aliens come to Earth and show us that some known NP-hard problem cannot be solved faster than O(n 100 ) time. Does this resolve the question of whether P = NP? (Explain briefly.) (j) Suppose that A P B, the reduction runs in O(n 2 ) time, and B can be solved in O(n 4 ) time. What can we infer about the time needed to solve A? (Explain briefly.) (k) True or False: If a graph G has a vertex cover of size k, then it has a dominating set of size k or smaller. (l) Suppose that A P B, and there is a factor-2 approximation to problem B. Which of the following necessarily follows? i. There is a factor-2 approximation for A. ii. There is a constant factor approximation for A, but the factor might not be 2. iii. We cannot infer anything about our ability to approximate A. (m) Recall that the Hadamard gate is described by the matrix 1 2 ( 1 1 1 1 ). Suppose the Hadamard gate is applied to a qubit in the state 1 5 ( 3 4 ) and the qubit is then measured in the computational basis. What is the probability of obtaining the outcome 0? 2. Minimum spanning trees and shortest paths. You are given a connected, undirected graph G = (V, E), where each edge (u, v) W is labeled with a nonnegative weight w(u, v). Suppose that we run Prim s MST algorithm starting at some source node s V. Let T be the resulting tree. You would like to know whether T is also the shortest path tree for the single-source node s. Of course, you could run Dijkstra s algorithm and compare the two trees, but this would take additional O(n log n + m) time, where n = V and m = E. Show that (once computed) it is possible to determine whether T is the shortest-path tree in only O(n + m) time. Your algorithm takes as input the graph G, a source vertex s, and (as in the output of Prim s algorithm) the tree T is represented by the values pr[v] for each v V. Your algorithm need only answer yes or no. You may assume that all edge weights and shortest path lengths are distinct. Justify your algorithm s correctness and derive its running time. 3. Scheduling to minimize average lateness. In class we presented a greedy algorithm for scheduling a set of n tasks, in which each task has a duration t i and deadline d i. We showed that scheduling the tasks in increasing order of deadline minimizes the maximum lateness. (Recall that if task i is scheduled at time s i, then its lateness is l i = max{0, s i + t i d i }.) Define the average lateness to be 1 n n i=1 l i. (a) Provide a counterexample to show that scheduling tasks in increasing order of deadline does not minimize average lateness. Briefly explain your example. (b) Provide a counterexample to show that scheduling tasks in increasing order of duration does not minimize average lateness. Briefly explain your example. (c) Suppose that we redefine lateness to be l i = s i + t i d i (ignoring the max ). Thus, if the task finishes before the deadline, its lateness is negative. (Intuitively, this can be thought of as a bonus, which can be applied to reduce the positive lateness of some other task.) Prove 2

that if tasks are scheduled in increasing order of duration, then average lateness (under this modified definition) will be minimized. (Hint: Use an exchange argument.) 4. Counting mixed-parity inversions. Given a list A = (a 1,..., a n ) of integers, a mixed-parity inversion is a pair a i and a j such that i < j, a i > a j, and a i and a j are of different parities. (In other words, it is an inversion in which one number is even and the other is odd.) Design an O(n log n)-time algorithm that counts the number of mixed-parity inversions in a list A containing n elements. Justify your algorithm s correctness and derive its running time. 5. Hamiltonian paths in tournaments. A tournament is a digraph G = (V, E) in which for each pair of vertices u and v, either there is an edge (u, v) or an edge (v, u), but not both. A directed Hamiltonian path is a path that visits every vertex in a digraph exactly once. (a) Prove that for all n 1, every tournament on n vertices has a directed Hamiltonian path. (Hint: Use induction on the number of vertices.) (b) Give an O(n 2 ) algorithm that, given a tournament, finds a Hamiltonian path. (You may assume either an adjacency list or an adjacency matrix representation of G.) 6. Bucket redistribution. You are given a collection of n blue buckets and n red buckets, denoted B i and R i for 0 i n 1. Initially each of the blue buckets contains some number of balls and each red bucket is empty. The objective is to transfer all the balls from the blue buckets into the red buckets, subject to the following restrictions. The input to the problem consists of two sequences of integers, (b 0, b 1,..., b n 1 ) and (r 0, r 1,..., r n 1 ). Blue bucket B i holds b i balls initially, and at the end, red bucket R i should hold exactly r i balls. The balls from blue bucket B i may be redistributed only among the red buckets R i 1, R i, and R i+1 (with indices taken modulo n). You may assume that i b i = i r i. Design a polynomial-time algorithm that, given the lists (b 0, b 1,..., b n 1 ) and (r 0, r 1,..., r n 1 ), determines whether it is possible to redistribute the balls from the blue buckets into the red buckets according to these restrictions. 7. Shuffles. You are given three strings X = x 1... x m, Y = y 1... y n, and Z = z 1... z p, where p = m + n. We say that Z is a shuffle of X and Y if it is possible to interleave the individual symbols of X and Y (without changing their relative order within each string) to obtain Z. Present an efficient algorithm that, given strings X, Y, and Z, determines whether Z is a shuffle of X and Y. Give a short proof of your algorithm s correctness and derive its running time. (Hint: Use dynamic programming. It suffices to present just the recursive formulation. It is possible to do this in O(mn) time.) 8. Partitioning. Suppose a shipping company wants to ship n objects of weights w 1,..., w n. Each weight is a positive integer. The company wants to partition these objects between two different ships so that the total weight of the two ships is as similar as possible. In particular, if W 1 is the 3

total weight of objects on Ship 1, and W 2 is the total weight on Ship 2, then the objective is to minimize the weight ratio, max{w 1, W 2 }/ min{w 1, W 2 }. Observe that this ratio is never smaller than 1, and it equals 1 if and only if the two ships are carrying identical total weights. Present an efficient algorithm that, given the weights {w 1,..., w n }, computes the optimum weight ratio. You can express your running time as a function of both n and the total weight W = n i=1 w i. (Hints: Use dynamic programming. You are not required to give the entire DP algorithm, just a recursive formulation. You need only compute the optimum weight ratio, not the actual partition. Justify your algorithm s correctness and derive its running time. Note that O(nW ) time is possible. It suffices to focus on computing the total weight carried by just one of the ships, since the other must carry all the remaining weight.) 9. Max flow. Consider the flow network shown below, and suppose that we have already computed a flow f on this network. In the diagram, each edge e is labeled with f(e)/c(e), where f(e) is the flow on this edge and c(e) is the capacity of the edge. a 1/4 2/3 3/3 s b 0/3 t 3/5 2/2 1/1 c (a) Show the residual network corresponding to this flow. (b) Show any augmenting path from s to t in the residual network. (c) Show the new flow that results by pushing as much flow as possible through this augmenting path. 10. Minimum cut with many terminals. You are given a directed graph G = (V, E) with a source vertex s and a set of terminal vertices T = t 1,..., t k. Present a polynomial-time algorithm to determine the minimum number of edges to remove so that there is no path from s to any of the terminals. Prove that your algorithm is correct and analyze its running time. 11. Can you hear me now? Part II. You are given a collection of n points U = {u 1, u 2,..., u n } in the plane, each of which is the location of a cell phone user. You are also given the locations of m cell towers, C = {c 1, c 2,..., c m }. A cell-phone user can connect to a tower if it is within distance of the tower. For the sake of fault-tolerance, each cell-phone user must be connected to at least three different towers. For each tower c i you are given the maximum number of users, m i, that can connect to this tower. 4

Give a polynomial-time algorithm that determines whether it is possible to assign all the cellphone users to towers, subject to these constraints. Prove its correctness. (You may assume you have a function that returns the distance between any two points in O(1) time.) 12. Pharmacy scheduling. Your local pharmacy has asked you to help set up the work schedule for the next month. There are n pharmacists on the staff and m work days in the month. Each pharmacist gives a list of the days of the month that he/she is available to work. For the ith pharmacist, this is given as a list A i, where each number in the list is in the range from 1 to m. Let d i = A i denote the number of days that pharmacist i is available to work. Then he/she should be scheduled to work at least d i /2 of these days. Each day there must be exactly 3 pharmacists on duty. Present an efficient algorithm that determines whether there exists a schedule that satisfies all the above requirements. Present a brief proof that your algorithm is correct. (Hint: Reduce to Max Flow.) 13. Balanced 3-coloring. Show that the following problem is NP-complete. Remember to show (1) that it is in NP and (2) that some known NP-complete problem can be reduced to it. Given a graph G = (V, E), where V is a multiple of 3, can G can be 3-colored such that the sizes of the 3 color groups are all equal to V /3? That is, can we assign an integer from {1, 2, 3} to each vertex of G such that no two adjacent vertices have the same color, and such that all the colors are used equally often? (Hint: Reduction from the standard 3-coloring problem.) 14. Angry knight seating. King Arthur has a large round table around which all his knights should sit. Unfortunately, some knights hate each other and thus cannot be seated next to each other. There are n knights, {v 1, v 2,..., v n }, and the king has given you a list of pairs of the form {v i, v j }, which indicates that knights v i and v j hate each other. The king asks you to write a program to determine if it is possible to seat the knights about the table. Instead, prove that the problem is NP-complete. 15. High-degree independent set. In the High-Degree Independent Set (HDIS) problem, you are given a graph G = (V, E) and an integer k, and you want to know whether G has an independent set V of size k such that each vertex of V is of degree at least k. (a) Show that HDIS is in NP. (b) Show that HDIS is NP-hard. (Hint: Use the standard independent set problem.) 16. Acyclic subgraph. In the acyclic subgraph problem, you are given a directed graph G = (V, E) and an integer k, and are asked to determine whether G contains a subset V of k vertices such that the induced subgraph on V is acyclic. (Recall that the induced subgraph on V is the subgraph G = (V, E ) whose vertex set is V, and for which (u, v) E if u, v V and (u, v) E. Hint: Try a reduction from Independent Set. Think of a reduction that maps undirected edges to directed cycles.) 5

17. Hamiltonian paths. Given an undirected graph G = (V, E), a Hamiltonian path is a simple path (not a cycle) that visits every vertex in the graph. The Hamiltonian Path problem is the problem of determining whether a given graph has a Hamiltonian path. (a) Show that Hamiltonian Path is in NP. (b) Observe that if a graph has a Hamiltonian Cycle, then it also has a Hamiltonian Path. Consider the following attempt to prove that Hamiltonian Path is NP-hard: given a graph G for the Hamiltonian Cycle problem, simply output a copy of this graph. Explain why this reduction is incorrect. (c) Prove that Hamiltonian Path is NP-hard. (Hint: You can give a reduction from the Hamiltonian Cycle problem.) 18. Approximate partitioning. Recall the Partition Problem (Problem 8 above). Consider the following heuristic for this problem. First, sort the objects by decreasing order of their weights. Initially both ships have 0 weight. Repeatedly, take the next object from the sorted list and put it on the ship whose total weight is the smaller of the two. (If they are tied, put it on Ship 1.) Update the weight of this ship. (a) Briefly explain how to implement this in O(n log n) time. (b) Give a small example that shows that this is not optimal. (c) Prove that for any input, this heuristic achieves an approximation ratio of at most 2. In other words, show that the weight ratio produced by this heuristic is at most twice as large as the weight ratio of the optimal solution. 19. Set cover approximation. The set cover optimization problem is as follows: Given a pair (X, S), where X is a finite set and a S = {s 1, s 2,..., s n } is a collection of subsets of X, find a minimum-sized collection of these sets whose union equals X. Consider a special version of the set cover problem in which each element of X occurs in at most three sets of S. Present an approximation algorithm for this special version of the set cover problem with a ratio bound of 3. Briefly derive the ratio bound of your algorithm. 20. Bottleneck TSP. Suppose you have a sequence of points X = x 1,..., x n sorted from left to right along a line. The distance between two points x i and x j is just their absolute difference x j x i. The bottleneck TSP is the following: Find a cycle that visits each point exactly once, such that maximum distance traveled between any two consecutive points is as small as possible. Consider the following alternating heuristic for this problem: Travel from x 1 to x n, skipping every other point. Then return from x n to x 1, visiting the skipped points. Prove that this heuristic provides a factor-2 approximation to the bottleneck TSP. (Hint: Let L be the maximum distance between any two consecutive points. Relate the costs of the optimum path and the heuristic path to L.) 6

21. Randomized approximation algorithm for 3-coloring. Suppose you are given an undirected graph G = (V, E) and are asked to color each of its vertices with one of three colors. We say an edge {u, v} E is satisfied if the colors assigned to u and v are different. In the optimization version of 3-coloring, your goal is to maximize the number of satisfied edges. Let c denote the maximum possible number of satisfied edges. Design a polynomial-time randomized algorithm with the property that the expected number of satisfied edges is at least 2 3 c. Establish your algorithm s running time and prove that it is correct. 22. Applying Karger s algorithm to the s-t cut problem. Recall that Karger s contraction algorithm finds the global minimum cut by repeatedly contracting random edges of a given input graph. To apply the same strategy to the s-t cut problem, we might try the following. At any iteration of the algorithm, let v s and v t denote the vertices corresponding to the subsets that contain vertices s and t, respectively. Since s and t should be on opposite sides of the cut, we delete any edges connecting v s and v t and select a random edge to contract among the remaining edges. Give an example showing that the probability of this algorithm finding a minimum s-t cut can be exponentially small. 7