CMPSCI 611 Advanced Algorithms Midterm Exam Fall 2015

Similar documents
COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017

COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

Econ 172A, Fall 2012: Final Examination (I) 1. The examination has seven questions. Answer them all.

CMPSCI611: The Matroid Theorem Lecture 5

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:

CSI 4105 MIDTERM SOLUTION

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

Midterm Exam 2 Solutions

Statistics 253/317 Introduction to Probability Models. Winter Midterm Exam Friday, Feb 8, 2013

Preparing for the CS 173 (A) Fall 2018 Midterm 1

CMPSCI 240: Reasoning Under Uncertainty First Midterm Exam

CPSC 320 Sample Final Examination December 2013

CS 170 Algorithms Spring 2009 David Wagner Final

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

One side of each sheet is blank and may be used as scratch paper.

CMPSCI 240: Reasoning Under Uncertainty First Midterm Exam

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

Quiz 1 Date: Monday, October 17, 2016

Algorithms Exam TIN093 /DIT602

University of California Berkeley CS170: Efficient Algorithms and Intractable Problems November 19, 2001 Professor Luca Trevisan. Midterm 2 Solutions

CSE 321 Solutions to Practice Problems

CS60007 Algorithm Design and Analysis 2018 Assignment 1

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Name: Student ID: Instructions:

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

Probability Notes (A) , Fall 2010

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science ALGORITHMS FOR INFERENCE Fall 2014

CS173 Lecture B, November 3, 2015

Even More on Dynamic Programming

Econ 172A, Fall 2012: Final Examination Solutions (I) 1. The entries in the table below describe the costs associated with an assignment

Dynamic Programming( Weighted Interval Scheduling)

Exact and Approximate Equilibria for Optimal Group Network Formation

1 Basic Definitions. 2 Proof By Contradiction. 3 Exchange Argument

We are going to discuss what it means for a sequence to converge in three stages: First, we define what it means for a sequence to converge to zero

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

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

CS 170 Algorithms Fall 2014 David Wagner MT2

Fall 2017 Qualifier Exam: OPTIMIZATION. September 18, 2017

Econ 172A, Fall 2012: Final Examination Solutions (II) 1. The entries in the table below describe the costs associated with an assignment

Math 110 (Fall 2018) Midterm II (Monday October 29, 12:10-1:00)

Proof Techniques (Review of Math 271)

CPSC 320 (Intermediate Algorithm Design and Analysis). Summer Instructor: Dr. Lior Malka Final Examination, July 24th, 2009

Practice Second Midterm Exam I

Lecture 2: Divide and conquer and Dynamic programming

UNIVERSITY OF YORK. MSc Examinations 2004 MATHEMATICS Networks. Time Allowed: 3 hours.

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

Algorithms and Data Structures (COMP 251) Midterm Solutions

Discrete Mathematics and Probability Theory Summer 2014 James Cook Midterm 1

Exact and Approximate Equilibria for Optimal Group Network Formation

HOMEWORK #2 - MATH 3260

Computer Science Foundation Exam

ACO Comprehensive Exam October 18 and 19, Analysis of Algorithms

Math 116 Second Midterm November 13, 2017

PGSS Discrete Math Solutions to Problem Set #4. Note: signifies the end of a problem, and signifies the end of a proof.

MATH 61-02: PRACTICE PROBLEMS FOR FINAL EXAM

December 2014 MATH 340 Name Page 2 of 10 pages

Designing Information Devices and Systems I Fall 2016 Babak Ayazifar, Vladimir Stojanovic Midterm 1. Exam location: 2050 VLSB, Last Name: Tong-Zzz

2 Generating Functions

MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics

McGill University Faculty of Science. Solutions to Practice Final Examination Math 240 Discrete Structures 1. Time: 3 hours Marked out of 60

CSE 421 Introduction to Algorithms Final Exam Winter 2005

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

2. A vertex in G is central if its greatest distance from any other vertex is as small as possible. This distance is the radius of G.

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

CS/ECE 374 Final Exam Study Problems Fall 2016

Work easier problems first. Write out your plan for harder problems before beginning them.

Graph Theory. Thomas Bloom. February 6, 2015

CS2223 Algorithms D Term 2009 Exam 3 Solutions

Chapter 1 Review of Equations and Inequalities

Notes on the Matrix-Tree theorem and Cayley s tree enumerator

Exercises. Template for Proofs by Mathematical Induction

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Math 51 Midterm 1 July 6, 2016

Do not open this exam until you are told to begin. You will have 75 minutes for the exam.

Designing Information Devices and Systems I Spring 2017 Babak Ayazifar, Vladimir Stojanovic Midterm 1

MATH 501: Discrete Mathematics

CS246 Final Exam, Winter 2011

Midterm 1. Name: TA: U.C. Berkeley CS70 : Algorithms Midterm 1 Lecturers: Anant Sahai & Christos Papadimitriou October 15, 2008

More Dynamic Programming

PageRank: The Math-y Version (Or, What To Do When You Can t Tear Up Little Pieces of Paper)

Midterm Exam 1 Solution

ACO Comprehensive Exam March 17 and 18, Computability, Complexity and Algorithms

Dynamic Programming: Matrix chain multiplication (CLRS 15.2)

Class Note #20. In today s class, the following four concepts were introduced: decision

Algorithm Efficiency. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University

Problem Set 3 Due: Wednesday, October 22nd, 2014

CS325: Analysis of Algorithms, Fall Midterm

CSE 355 Test 2, Fall 2016

Solution Set 2. Problem 1. [a] + [b] = [a + b] = [b + a] = [b] + [a] ([a] + [b]) + [c] = [a + b] + [c] = [a + b + c] = [a] + [b + c] = [a] + ([b + c])

Greedy Algorithms My T. UF

Designing Information Devices and Systems I Fall 2016 Babak Ayazifar, Vladimir Stojanovic Midterm 1. Exam location: 145 Dwinelle, last SID# 2

ECS 20: Discrete Mathematics for Computer Science UC Davis Phillip Rogaway June 12, Final Exam

Homework 1 2/7/2018 SOLUTIONS Exercise 1. (a) Graph the following sets (i) C = {x R x in Z} Answer:

CS280, Spring 2004: Final

Calculator Exam 2009 University of Houston Math Contest. Name: School: There is no penalty for guessing.

2013 University of New South Wales School Mathematics Competition

Shortest paths with negative lengths

Problem #1 #2 #3 #4 Extra Total Points /3 /13 /7 /10 /4 /33

Transcription:

NAME: CMPSCI 611 Advanced Algorithms Midterm Exam Fall 015 A. McGregor 1 October 015 DIRECTIONS: Do not turn over the page until you are told to do so. This is a closed book exam. No communicating with other students, or looking at notes, or using electronic devices. You may ask the professor or TA to clarify the meaning of a question but do so in a way that causes minimal disruption. If you finish early, you may leave early but do so as quietly as possible. The exam script should be given to the professor. There are six questions. All carry the same number of marks but some questions may be easier than others. Don t spend too long on a problem if you re stuck you may find that there are other easier questions. The front and back of the pages can be used for solutions. There are also a blank page at the end that can be used. If you are using these pages, clearly indicate which question you re answering. Further paper can be requested if required. However, the best answers are those that are clear and concise (and of course correct). 1 /10 /10 3 /8+ 4 /10 5 /10 6 /10 Total /58+ 1

Question 1 (The True or False Question). For each of the following statements, say whether they are TRUE or FALSE. No justification is required. 1. If a subset system satisfies the exchange property, it also satisfies the cardinality property. Answer: True.. Given a connected, undirected graph, let D be the diameter and let M be the size of the maximum matching. Then M D/. Answer: True. If the diameter is D there must be a path of length D in the graph that doesn t repeat any nodes. Taking alternating edges on this path gives a matching. 3. Given a matroid (E, I) there is at most one maximal solution i I. Answer: False. For example, if E = {a, b, c} and I = {{}, {a}, {b}, {c}} then {a}, {b}, {c} are each maximal. 4. In a bipartite graph there are no cycles with an odd number of edges. Answer: True. 5. Given a undirected weighted graph G, let T be a minimum spanning tree. Then the length of the shortest path between u and v in G equals the length of the shortest path between u and v in T. Answer: False. For example, consider the complete graph on three nodes with edge weights,, and 3. Question (Grid Graphs). In this question, we develop an alternative shortest path algorithm for a specific type of graph. In a grid graph there are n = k nodes labelled v i,j where i and j range between 1 and k. For each i < k there is a down edge of length d i,j from v i,j to v i+1,j. For each j < k there is an across edge of length a i,j from v i,j to v i,j+1. For example, a possible graph for n = 9 is v 1,1 1 v 1, 3 v 1,3 5 1 v,1 3 v, 4 v,3 1 6 v 3,1 v 3, 3 v 3,3 and in this graph, for example, the across edge from v,1 to v, has length a,1 = 3. 1. What is the length of the shortest path from v 1,1 to v 3,3 in the above example? Answer: The length of the shortest path is + 1 + + 3 = 8.. Let d[i, j] be the length of the shortest path from v i,j to getv k,k. If i > k or j > k, let d[i, j] =. Give a formula for d[i, j] in terms of d[i + 1, j] and d[i, j + 1]. Justify your answer.

Answer: 0 if i = k, j = k a i,j + d[i, j + 1] if i = k, j < k d[i, j] = d i,j + d[i + 1, j] if i < k, j = k min(a i,j + d[i, j + 1], d i,j + d[i + 1, j]) if i < k, j < l because the shortest path from v i,j to v k,k is either via v i,j+1, and will have length a i,j + d[i, j + 1], or via v i+1,k, and will have length d i,j + d[i + 1, j]. If both nodes exist d[i, j] is the minimum of these two quantities. If only one of these nodes exist, d[i, j] equals the corresponding distance. If neither exists i = k, j = k and hence d[i, j] = 0. 3. Design an algorithm that computes d[1, 1]. Prove the running time and correctness. Answer: (a) Let d[k, k] = 0 (b) For r = k 1,..., i. For i, j such that i + j = r, let d[i, j] be updated using the formula above. (c) Return d[1, 1]. The correctness of the formula for d[i, j] is argued above and by computing d[i, j] in decreasing order of i + j we ensure d[i + 1, j] and d[i, j + 1] have already been computed when there values are required to set d[i, j]. The running time is O(n) since there are n values d[i, j] to compute and each can be computed in O(1) time given the previously computed values. 4. Any path from v 1,1 to v k,k will use exactly k 1 down edges and k 1 across edges. Suppose we add the constraint that we only allow a path where the sub-path from v 1,1 to any intermediate node on the path uses at least as many across edges as down edges. How would you modify your algorithm to find the shortest such path? Answer: For i > j, we change the formula to d[i, j] =. This ensures that d[i, j] for i j always corresponds to path that does not visit a node v k,l where k > l. Question 3 (Planning Your Working Vacation). Suppose you are a ski instructor and that you plan to work at a European ski resort for some part of the n-day ski season next year. Unfortunately, there isn t enough work for you to be paid every day and you need to cover your own expenses. Fortunately, you know in advance that if you are at the resort on the ith day of the season, you ll make p i euros where p i could be negative (if expenses are more than earnings) or positive (if expenses are less than earnings). To maximize your earning you should choose carefully which day you arrive and which day you leave; the days you work should be consecutive and you don t need to work all season. For example, if n = 8 and p 1 = 9, p = 10, p 3 = 8, p 4 = 10, p 5 = 5, p 6 = 4, p 7 =, p 8 = 5 then if you worked from day to day 5, you would earn 10 8 + 10 + 5 = 17 euros in total. 1. Give a divide and conquer algorithm for this problem that runs in O(n log n) time. You may assume n is a power of two. If your algorithm takes longer or doesn t use divide and conquer you might get partial credit. 3

Answer: Let a and b be the maximum possible earning from the first and second half of the season respectively. The c be the maximum possible earning that includes both days n/ and n/ + 1. Then the maximum possible earning is max(a, b, c). We compute a and b recursively where the base case when considering single day i is max(p i, 0). To compute c, let c 1 be the earning from an interval that ends with the n/th day and let c be maximum earning from an interval that starts with the (n/ + 1)th day. Let c = c 1 + c. We compute c as follows (a) Let total = p n/+1 and c = p n/+1. (b) For i = n/ +,..., n, let total = total + p i and c = max(c, total). and c 1 is computed analogously.. Justify why your algorithm is correct and analyze the running time. Answer: Let T (n) be the time to compute max(a, b, c). Then T (n) T (n/) + O(n) since computing a and b takes T (n/) time and computing c takes O(n) time. Hence, by the Master Theorem, T (n) = O(n log n). Correctness: The fact that the max possible earning is max(a, b, c) follows since every possible interval is either a subset of the first or second half of the season or includes day n/ and n/ + 1. c = c 1 + c because the best interval that includes day n/ and n/+1 and be decomposed into the best interval that ends on day n/ and the best interval that starts on day n/ + 1. 3. Extra Credit: Design an O(n) time algorithm for this problem. Answer: Let e(t) be the earnings of the best interval that is either empty or ends on the tth day. Then, e(t) = max(e(t 1) + p t, 0) since the best corresponding interval is either empty or includes the interval corresponding to e(t 1) and {t}. The best interval is then s = max 1 i n e(i). We compute s as follows: (a) Let e = 0 and s = 0. (b) For i = 1,..., n, let e = max(e + p i, 0) and s = max(s, e). At the end of iteration t, e = e(t) and s = max 1 i t e(t). Hence, at the end of the algorithm s = max 1 i n e(i) as required. The running time is O(n) since there are n iterations and each takes O(1) time. Question 4 (Triangles and Four Cycles). Given an undirected graph G on n nodes, a triangle in the graph is a set of three different nodes {u, v, w} such that there are edges between each of these nodes. For example, in the following graph {b, c, d} is a triangle. a b c e d 1. List the other triangles in the above graph. Answer: The other triangles are {b, d, e}, {b, c, e}, and {c, d, e}. 4

. Design an O(n ω ) time algorithm that returns the number of triangles in a graph where O(n ω ) is the running time of an algorithm that multiplies two n n matrices. Recall ω <.38. Analyze the running time and prove your algorithm is correct. Hint: If M is the adjacency matrix of G, first consider computing M M. Answer: First note that M [i, j] = k M[i, k]m[k, j] = (#number of length two paths from i to j) and therefore the number of triangles that include the nodes i and j is M [i, j]m[i, j] since there are M [i, j] triangles if there is an edge between i and j and 0 triangles otherwise. Hence the total number of triangles is i<j M [i, j]m[i, j] 3 where the division by three is because there are three ways to pick two nodes in the triangle. The time to compute M is O(n ω ) and computing the sum takes O(n ) time. (Another way to solve the problem is to compute M 3 ; the some of the diagonal elements equals 6 times the total number of triangles.) 3. A four-cycle is a set of four different nodes {u, v, w, x} such that there is an edge between u and v, v and w, w and x, and x and u (there may also be additional edges between the nodes). For example, in the example earlier, {b, c, d, e} is a four-cycle. Design an O(n ω ) time algorithm that returns the number of four-cycles in a graph. Answer: As above M [i, j] is the number of length two paths between i and j. Hence the number of four cycles where i and j are not adjacent in the cycle is ( ) M [i,j]. Hence, the number of four cycles is i<j ( M ) [i,j] where the division by two is to adjust for double counting because there are two ways to pick two non-adjacent nodes on a four cycle. The time to compute this quantity is O(n ω + n ) = O(n ω ) as above. Question 5 (Planning A Party). Alice wants to throw a party and is deciding whom to call. She has n (which is at least 11) people to choose from, and she has made up a list of which pairs of these people know each other. She wants to invite as many people as possible subject to the following two constraints: 1. Every person invited should know at least five other people that are invited.. Every person invited should not know at least five other people that are invited. Design an efficient algorithm for maximizing the number of people she can invite. Remember to analyze the running time and correctness. Hint: Maximizing the number of invitees is the same as minimizing the number of people Alice doesn t invite. Obviously Alice might not be able to invite everyone. For example, if one of the n people knows less than five people out of the n potential invitees then the first constraint can never be satisfied for that person. Answer: Label the people that could be invited 1,... n. For a subset S of {1,,..., n}, define K i (S) to be the number of people in S that the ith person knows and define D i (S) be the number of people in S that the ith person doesn t know. Then the algorithm is: 5

Let P = {1,,..., n} be the set of potential invitees. While there exists i P such that K i (P ) < 5 or S i (P ) < 5: P P \ {i}. Return P. Correctness: For all people in the final set P (which could be empty), there are at least 5 people they don t know in P and 5 people they do know in P. Hence, inviting all people in P satisfies Alice s constraints. Suppose the optimal set of invitees is P opt. We use induction on the number of people we remove to prove P always contains P opt. Initially, when we have removed 0 people, P contains P opt. Assume after removing k people, P contains P opt. If we remove a (k + 1)th person then this person can not have been in P opt since if K i (P ) < 5 or D i (P ) < 5 then K i (P opt ) < 5 or D i (P opt ) < 5. Hence P opt is still contained in P. The running time is O(n ). There are O(n) iterations and in each we need to scan through the P n remaining possible invitees to find if there is an i such that K i (P ) < 5 or S i (P ) < 5. If so, we need to update P 1 values of K j and S j. Question 6 (Independent Sets in Trees). Given a graph G, we say a set of nodes S is independent if there are no edges in G between any two nodes in S. In this question we consider the problem of computing independent sets when G is a tree. For example, in the following tree, a b c d e f g h i the set S = {b, g, h, d} is an independent set. Suppose every node v has a weight w(v). Design and analyze an algorithm for finding an independent set S in a tree such that v S w(v) is maximized. Remember to analyze the running time and prove correctness. Hint: Consider a dynamic problem where there are n subproblems and each corresponds to finding the maximum weight independent set restricted to a node and its decedents. For example, in the subproblem for node c we are interested in finding the maximum weight independent subgraph amongst the nodes {c, g, h}. Answer: Let T (u) be the subtree rooted at u and let S(u) be the maximum weight independent set of T (u). Then S(u) = max w(u) + S(w), S(v) w is a grandchild of u v is a child of u because either u is in the maximum weight independent set of T (u) or it isn t. If it is, then none of the children of u are also in the set and so the largest weight independent set also includes the largest weight independent sets of T (w) for all w that are grandchildren of u. If it isn t, the largest weight independent set also includes the largest weight independent sets amongst v and its descendants for all v that are children of u. 6

For each node u, let height(u) be the maximum length of the shortest path from u to a descendent of u. The algorithm is as follows: 1. For h = 0, 1,... (a) Let S(u) = max (w(u) + ) w is a grandchild of u S(w), v is a child of u S(v). Return S(r) where r is the root of the tree. Since we compute S( ) in order of increasing height, we will have computed S( ) for the children and grandchildren of u before we need these values to compute S(u). The running time is O(n) since there are n values of S( ) to compute and each value is needed to compute other values of S( ) (every node has at most one parent and one grand parent). 7