Algorithms and Data Structures (COMP 251) Midterm Solutions

Similar documents
Omega notation. Transitivity etc.

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:

Ma/CS 6b Class 3: Stable Matchings

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

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

CS 598RM: Algorithmic Game Theory, Spring Practice Exam Solutions

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

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

Combinatorial Optimisation, Problems I, Solutions Term /2015

Matching Residents to Hospitals

Ma/CS 6b Class 3: Stable Matchings

Dynamic Programming: Shortest Paths and DFA to Reg Exps

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

Exam Practice Problems

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

(1) Which of the following are propositions? If it is a proposition, determine its truth value: A propositional function, but not a proposition.

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Algorithm Design and Analysis

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Discrete Mathematics and Probability Theory Summer 2014 James Cook Midterm 1 (Version B)

CSI 4105 MIDTERM SOLUTION

Bipartite Matchings and Stable Marriage

CMPSCI 611 Advanced Algorithms Midterm Exam Fall 2015

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

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

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

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

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

Midterm 1. Total. CS70 Discrete Mathematics and Probability Theory, Spring :00-9:00pm, 1 March. Instructions:

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

ICS 252 Introduction to Computer Design

More on NP and Reductions

PROBLEMS OF MARRIAGE Eugene Mukhin

Assignment 3 Logic and Reasoning KEY

6.2b Homework: Fit a Linear Model to Bivariate Data

COMP251: Bipartite graphs

Lecture 14 - P v.s. NP 1

Ring Sums, Bridges and Fundamental Sets

1 Some loose ends from last time

Discrete Mathematics, Spring 2004 Homework 9 Sample Solutions

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.

Matching Problems. Roberto Lucchetti. Politecnico di Milano

Exam in Discrete Mathematics

CPSC 320 Sample Final Examination December 2013

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

COMP251: Bipartite graphs

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

CSC2556. Lecture 5. Matching - Stable Matching - Kidney Exchange [Slides : Ariel D. Procaccia]

Discrete Mathematics and Probability Theory Summer 2014 James Cook Midterm 1

Question Paper Code :

MAT 300 RECITATIONS WEEK 7 SOLUTIONS. Exercise #1. Use induction to prove that for every natural number n 4, n! > 2 n. 4! = 24 > 16 = 2 4 = 2 n

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

CSE 421 Introduction to Algorithms Final Exam Winter 2005

Math 113 Winter 2013 Prof. Church Midterm Solutions

Homework Assignment 1 Solutions

Matchings in Graphs. Definition 3 A matching N in G is said to be stable if it does not contain a blocking pair.

Greedy Homework Problems

Reexam in Discrete Mathematics

Mathematics for Computer Science MATH 1206C [P.T.O] Page 1 of 5

Introduction to Algorithms

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

Algorithm Design Strategies V

Exam in Discrete Mathematics

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

Introduction to Algorithms

Discrete Mathematics and Probability Theory Summer 2015 Chung-Wei Lin Midterm 1

Do not turn this page until you have received the signal to start. Please fill out the identification section above. Good Luck!

2 hours THE UNIVERSITY OF MANCHESTER. 6 June :45 11:45

Matching Problems. Roberto Lucchetti. Politecnico di Milano

ACO Comprehensive Exam 19 March Graph Theory

CS60007 Algorithm Design and Analysis 2018 Assignment 1

Greedy Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 10

Lecture 5: The Principle of Deferred Decisions. Chernoff Bounds

Trees. A tree is a graph which is. (a) Connected and. (b) has no cycles (acyclic).

Math 391: Midterm 1.0 Spring 2016

1. (a) Explain the asymptotic notations used in algorithm analysis. (b) Prove that f(n)=0(h(n)) where f(n)=0(g(n)) and g(n)=0(h(n)).

CS 6301 PROGRAMMING AND DATA STRUCTURE II Dept of CSE/IT UNIT V GRAPHS

NP and Computational Intractability

CS 170 Algorithms Spring 2009 David Wagner Final

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

Chapter 7 Matchings and r-factors

CPSC W1: Midterm #1 Sample Solution

Algorithm Design and Analysis

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

An Efficient Algorithm for Batch Stability Testing

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

Single Source Shortest Paths

Introduction to Algorithms

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

CS325: Analysis of Algorithms, Fall Final Exam

MATH 114 Fall 2004 Solutions to practice problems for Final Exam

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

Algorithm Design and Analysis

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Agenda. Soviet Rail Network, We ve done Greedy Method Divide and Conquer Dynamic Programming

HOMEWORK #2 - MATH 3260

CSCE 551 Final Exam, April 28, 2016 Answer Key

SF2972 Game Theory Exam with Solutions March 15, 2013

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

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

Transcription:

Algorithms and Data Structures COMP 251) Midterm Solutions March 11, 2012 1. Stable Matching Problem a) Describe the input for the stable matching problem. Input: n men and n women. For each man, there would be a preference list ranking each woman in order, and for each woman, there would be a preference list ranking each man in order, i.e., 2n permutations of {1, 2,..., n}. b) Consider two matched paris m, w) and m, w ) in a matching of n men and n women. Dene what it means for m, w ) to be an instability. An instability in this case means a man m ranks woman w higher than w and a woman w ranks man m higher than m. c) True or False Give proof or counterproof). Suppose in a stable marriage problem with n men and n women, a man m is ranked rst on the list of a woman w, and w is ranked rst on the list of man m. Claim: m, w) is a matched pair in every stable matching. True. Suppose not, then there is an instability. If it is m, w ), then w is ranked higher than w by m, which is a contradiction since rank w) = 1 for ) m. If it is m, w, then m is ranked higher than m by w, which is a contradiction since rank m) = 1 for w. 1

2. Growth Rate and Divide and Conquer a) Rank the following list of functions in increasing order of growth rate, i.e., if f n) is ranked before g n), then f n) = O g n)). i)n 2 ii)n 21/10 iii) 21/10) n iv) 21n v) 3 n 21n, n 2 logn, n 21/10, 21/10) n, 3 n. b) Calculate directly T 16) where: T 2) = 2T 1) + 4 = 8 T 4) = 2T 2) + 8 = 24 T 8) = 2T 4) + 16 = 64 T 16) = 2T 8) + 32 = 160 T 2n) = 2T n) + 4n, T 1) = 2 c) Prove for any k > 0 that T 2 k) = k + 1) 2 k+1, where T is dened as in 2b). By induction: k = 0, T 2 0) = T 1) = 1.2 1 = 2 Assume for k 0, T 2 k) = k + 1) 2 k+1 For k + 1, T 2 k+1) = 2T 2 k+1) + 2 k+2 = 2 k + 1) 2 k+1 + 2 k+2 = k + 2) 2 k+2. 2

3. Graphs a) Describe what is meant by breadth rst search of a graph. Illustarate on a graph with about 6-8 nodes. Let G = V, E) and let u ɛ V be any vertex. Set L 0 = {u}. We dene L j by choosing all vertices not yet chosen that are adjacent to vertices in L j 1, for j = 1, 2, 3,... b) A prof wants to divide her n students into two study groups. For each student X she has a list of students she does not want in the same study group as X. Give a linear time algorithm that either outpus two study groups with the desired property, or shows that this is not possible. Illustrate with a small example for each case. Let the students be {1, 2,..., n} and the groups be A and B. Put 1 ɛ A. Do a BFS from 1. If j=even, L j is in A else L j is in B. If there is any edge inside L j, then the answer is NO. The graph above shows a NO case. If there are remaining nodes, keep doing BFS until all students are placed, i.e., original graph is disconnected. The graph below shows a YES case. 3

4. Greedy Algorithms a) Does Dijkstra's shortest path algorithm work correctly when the input, which is a directed graph, can have negative edge weights? Give a proof or counter example, and justify your answer. No. E.g., consider the graph, To nd the shortest path, Dijkstra computes d s, t)=4, using the two edges costing 2 each as shown below, but it actually is 1, obtained by 6 + 5)). b) You are given a connected, undirected graph where the vertices are routers and the edges are communication links between routers. For each edge there is a cost associated. It is required to connect all the routers together as cheaply as possible, without spending more than k dollars on any given link. Name an algorithm that was presented in class that could be used, and argue why it correctly solves this problem. Kruskal's algorithm. First, the edges are ranked by increasing weights w 1 w 2... w m, where m is the total number of edges. Kruskal's algorithm takes edges in this order until a spanning tree is found. If the last edge chosen, w t k, we are done. If not, then w t > k, but by construction the edges with weights > k do not form a spanning tree. 4

5. Dynamic Programming The input for the sushi problem are positive integers n,b,c 1,c 2,...,c n and p 1,p 2,...,p n. There are n pieces of sushi labelled 1,2,...,n. For each i=1,2,...,n, piece i costs c i dollars and gives you p i units of pleasure when you eat it. Your goal is to maximiaze your total eating pleasure by spending at most B dollars on shushi. a) Let M j, k) be the maximum pleasure you can obtain with the budget of k dollars and can choose from pieces of sushi labelled 1,2,...,j. Write down a dynamic programming recursion to compute M j, k) for j=1,2,...,n and k=1,2,...,b. M 0, k)=0, k=0,...,b. for j=1,...,n for k=0,...,b M j, k)=max{m j 1, k), p j + M j 1, k c j )}. b) Consider the input data n=4, B=8, c 1 =2, c 2 =4, c 3 =6, c 4 =3 and p 1 =1, p 2 =6, p 3 =9, p 4 =5. Write down the table of values M j, k) for j=1,2,3,4 and k=1,2,...,8. 0 1 2 3 4 5 6 7 8 Ø 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1,2 0 0 1 1 6 6 7 7 7 1,2,3 0 0 1 1 6 6 9 9 10 1,2,3,4 0 0 1 5 6 6 9 11 11 5