CMSC Theory of Algorithms Second Midterm

Similar documents
CMPSCI 311: Introduction to Algorithms Practice Final Exam

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

Solution for Homework set 3

UML CS Algorithms Qualifying Exam Fall, 2003 ALGORITHMS QUALIFYING EXAM

Exam 3 Practice Problems

Chapter 9 Graph Algorithms

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

Chapter 9 Graph Algorithms

CS521 \ Notes for the Final Exam

1. [5 points each] True or False. If the question is currently open, write O or Open.

Chapter 9 Graph Algorithms

Introduction to Algorithms. Lecture 24. Prof. Patrick Jaillet

Questions Total Points Score

Solutions for the Exam 6 January 2014

Student number: Datenstrukturen & Algorithmen page 1

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Binary Relations McGraw-Hill Education

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

Introduction to Graph Theory

Theorem 2.9: nearest addition algorithm

CS 170 Algorithms Spring 2009 David Wagner MT2

UML CS Algorithms Qualifying Exam Fall, 2004 ALGORITHMS QUALIFYING EXAM

CS525 Winter 2012 \ Class Assignment #2 Preparation

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

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Introduction to Algorithms April 21, 2004 Massachusetts Institute of Technology. Quiz 2 Solutions

Discrete Math: Selected Homework Problems

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

Final Exam May 8, 2018

UNIVERSITY OF TORONTO Department of Computer Science April 2014 Final Exam CSC373H1S Robert Robere Duration - 3 hours No Aids Allowed.

Problem Pts Score Grader Problem Pts Score Grader

END-TERM EXAMINATION

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

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

COMPSCI 311: Introduction to Algorithms First Midterm Exam, October 3, 2018

Discrete Mathematics and Probability Theory Fall 2015 Rao Midterm 1

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

FINAL EXAM SOLUTIONS

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.

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

CSE Qualifying Exam, Spring February 2, 2008

Lecture 22 Tuesday, April 10

context. (Similarly, we write ν for ν(g), etc. if there is no risk of confusion.) For a subset A V we write N G (A) = {v V ( w A)(v w)} (the set of

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

Problem Score Maximum MC 34 (25/17) = 50 Total 100

L.J. Institute of Engineering & Technology Semester: VIII (2016)

8.1 Polynomial-Time Reductions

Problem Set 9 Solutions

Graph Algorithms (part 3 of CSC 282),

Exam Datenstrukturen und Algorithmen D-INFK

Multiple-choice (35 pt.)

Week 12: Minimum Spanning trees and Shortest Paths

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

Mathematics Masters Examination

CSE 332 Winter 2018 Final Exam (closed book, closed notes, no calculators)

Graph Algorithms (part 3 of CSC 282),

8 Matroid Intersection

Part II. Graph Theory. Year

Final. Name: TA: Section Time: Course Login: Person on Left: Person on Right: U.C. Berkeley CS170 : Algorithms, Fall 2013

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

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Question Score Points Out Of 25

COS 226 Algorithms and Data Structures Fall Final

Student number: Datenstrukturen & Algorithmen page 1

On Universal Cycles of Labeled Graphs

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1

Algorithms CMSC Homework set #2 due January 21, 2015

CPSC 320 Midterm #1. February 4, 2015

Algorithms Exam TIN093/DIT600

r=1 The Binomial Theorem. 4 MA095/98G Revision

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Student Name and ID Number. MATH 3012 Final Exam, December 11, 2014, WTT

CS 373: Combinatorial Algorithms, Spring 1999

Module 2: NETWORKS AND DECISION MATHEMATICS

COS 226 Final Exam, Spring 2009

Reductions. Linear Time Reductions. Desiderata. Reduction. Desiderata. Classify problems according to their computational requirements.

Homework 4 Solutions

Notes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red.

UML CS Algorithms Qualifying Exam Spring, 2004 ALGORITHMS QUALIFYING EXAM

MC302 GRAPH THEORY SOLUTIONS TO HOMEWORK #1 9/19/13 68 points + 6 extra credit points

CS 374 Fall 2014 Homework 5 Due Tuesday, October 14, 2014 at noon

Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks

Midterm CSE 21 Spring 2012

COS 226 Algorithms and Data Structures Fall Final Solutions. 10. Remark: this is essentially the same question from the midterm.

Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand Midterm 1

Introduction to Algorithms April 16, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2

Ideally your algorithms for both parts should run in linear time. You will receive partial credit for a polynomial-time algorithm.

CMPSCI611: The SUBSET-SUM Problem Lecture 18

RYERSON UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE CPS 616 MIDTERM WINTER 2017

DESIGN AND ANALYSIS OF ALGORITHMS

HMMT February 2018 February 10, 2018

ENGI 4892: Data Structures Assignment 2 SOLUTIONS

Discrete mathematics , Fall Instructor: prof. János Pach

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

Introduction to Sets and Logic (MATH 1190)

CS 170 Second Midterm ANSWERS 7 April NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt):

2 hours THE UNIVERSITY OF MANCHESTER. 22 May :00 16:00

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Parameterized graph separation problems

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

Transcription:

NAME (please PRINT in large letters): SECTION: 01 02 (circle one) CMSC 27200 Theory of Algorithms Second Midterm 02-26-2015 The exam is closed book. Do not use notes. The use of ELECTRONIC DEVICES is strictly forbidden. Use the paper provided. Do not use your own paper. You may continue on the reverse side of each sheet. SHOW ALL YOUR WORK. Correct conclusions that come out of the blue (details of calculation missing) will not receive credit. Please be accurate and concise. When writing pseudocode, keep with simple instructions and notation, do not use notation specific to some programming languages. Define your variables and comment on each line, what is happening. You do NOT need to prove correctness of your algorithms unless specifically asked. Warning: The extra-credit (XC) problems are underrated; do the ordinary problems before you attempt the extra-credit problems. This exam contributes 20% to your course grade. The total point value of the ordinary (non-extra-credit) problems is 200 points. The extra-credit problems, as their name suggests, add to your score. 1

1. (1 point) Spell the singular of the word vertices. 2. (a) (6 points) Prove: the function 2 n is not polynomially bounded in n, i. e., there is no constant C such that 2 n = O(n C ). (b) (12 points) Recall the Integer Knapsack problem: INPUT: a list of n positive integers w 1,..., w n (the weights); a list of n positive integers v 1,..., v n (the values); a positive integer W (the weight limit). GOAL: maximize the value v i over all subsets i I I {1,..., n} satisfying the constraint i I w i W. OUTPUT: this maximum value. We solved this problem in O(nW ) steps using dynamic programming. Prove: this is NOT a polynomial-time algorithm. Explanation: You need to construct an infinite set of instances where the algorithm takes more than polynomial time. 2

3. (5+5+5+5+5+3+3 points) (polynomial time) For each function below, decide whether or not it is computable in polynomial time. The input is the number n in binary. Clearly state your answers: YES or NO. Prove your NO answers to the extent current knowledge permits. If your answer is YES, briefly sketch an algorithm (either in clear English or in pseudocode or a combination of these). Prove that it runs in polynomial time. Use algorithmic principles studied in class; do not use Newton s method. The goal is not to state the most efficient algorithm but the simplest algorithm that justifies the polinomial time claim. Prove that your algorithm runs in polynomial time. (a) n! (b) ( ) n (c) ( ) 2n (d) n lg n (e) n (f) the smallest 5 n prime factor of n (g) π(n) (the number of primes n) 3

4. (a) (XC, 5 points) Let B be a Bernoulli trial with probability p of success. (So X is a random variable that takes values 0 and 1 with P (B = 1) = p.) Repeat B until the first success; let X denote the number of times B was performed. Prove: E(X) = 1/p. (b) (10 points) Alice needs to find a random n-digit prime. (Digits are in binary; initial zeros are permitted.) She keeps trying random n-digit numbers until she finds one that is prime. (She has a primality tester.) Let X denote the number of times she tries. Asymptotically evaluate E(X) (as a function of n). Your answer should be of the form E(X) an b c n ; determine the constants a, b, c. Justify your answer. You may use part (a) without proof. 4

5. (15 points) (Min-cost connected spanning subgraph) Let G = (V, E, w) be a connected undirected weighted graph where w : E R is the weight function. (Negative weights are permitted.) Our goal is to find a subset F E of the edges such that the subgraph (V, F ) is connected; and minimize the total weight of such a subset. Design an algorithm that finds such a subset in Dijkstra time O( V log V + E ) (the optimal time bound for Dijkstra s algorithm). Describe your algorithm in unambiguous, concise English, no pseudocode needed. Briefly justify (a) optimality and (b) the time bound. 5

6. (25 points) (Dijkstra with a twist) We are given a weighted digraph with a source vertex, G = (V, E, s, w) where s V is the source and w : E R is the weight function. All weights are non-negative. We are also given a partition of the edges into red and blue edges: E = R B, where R B =. For all vertices v V find the minimum cost of reaching v from s along a path that uses at most one red edge. Your algorithm should run in Dijkstra time. Instruction: do not invent a new algorithm; apply an algorithm studied in class to an input other than G. Your job is to construct the new input. Describe your construction in unambiguous English and mathematical formulas. No pseudocode needed. 6

7. (5+5+5 points) (The complexity class P) For each problem below decide whether or not is belongs to the complexity class P. Clearly state your answer (YES or NO). Reason your answers. In the case of YES answers, sketch (in English) and name the algorithm involved in the justification of your answer. Make an accurate statement of the running time and justify it. All integers are given in binary. (a) compute the gcd of a pair of integers (b) given a weighted digraph with integer weights, decide whether or not there is a negative cycle (c) given the integers a and m, decide whether or not a has a multiplicative inverse modulo m. 7

8. (5+5+3+8+10 points) (Jarník vs. Dijkstra) Recall that Jarník s (a.k.a. Prim s) algorithm solves the min-cost spanning tree problem. (a) State exactly the input that Jarník s algorithm takes; compare it item by item with the input taken by Dijkstra s algorithm. Pay special attention to whether the graph is directed or undirected, whether the weights need to be non-negative; whether the input specifies a source node; connectivity issues. (b) Describe the output of (b1) Dijkstra s (b2) Jarník s algorithm (c) State the three data structure operations used, and how many times each was used (upper bound) in each algorithm (d) Recall the last and decisive relative loop invariant for Dijkstra: for each v V, the quantity c(v) is the min cost of all s v paths that pass through black vertices only (except for v itself). State the analogous loop invariant for Jarník. Do not prove. (e) Describe Jarník s algorithm in pseudocode. Define your variables. Indicate where the code differs from Dijkstra s. (Use the reverse side of this sheet.) 8

9. (8+3+3+3+3 points) (loop invariants) (a) Give an exact definition of a loop invariant. Include the definition of the configuration space. Make sure to state the domain of your predicates and the domain and range of your functions. (b) The body of Dijkstra s algorithm is a single while loop. For each statement below, decide whether or not it is a loop invariant. Briefly justify your answers. (The vertices are denoted v 1,..., v n.) (b1) Vertex v 7 is black. (b2) Vertex v 7 is white. (b3) c(v 7 ) 5.95. (c denotes the current cost.) (b4) The quantity c(v 7 ) cannot increase. 9

10. (5 points) Spell out the acronym NP. 11. (15 points) All graphs in this problem are undirected. Recall that a legal coloring of a graph an assignment of colors to the vertices such that adjacent vertices always get different colors. We say that a graph is k-colorable if it has a legal coloring with k colors. Let k-col denote the decision problem that takes an undirected graph as input and decides whether or not it is k-colorable. Give a Karp-reduction from 3-COL to 4-COL. Explanation. Given a graph G, you need to construct in polynomial time a graph f(g) such that f(g) is 4-colorable if and only if G is 3-colorable. Explain yor algorithm in English, no pseudocode required. You need to justify the if and only if statement. 10

12. (14 points) A palindromic string is a string that reads the same forward and backward; for instance ABBA, ACA, AAAAA are palindromic strings but ABAB is not. By a substring we mean a contiguous substring; for instance, given the string ABCDE, the strings ABC and BCDE are substrings but ACDE is not. Given a string of length n over the English alphabet, find the length of the longest palindromic substring. (Example: the word GATTACA includes the following palindromic substrings of length 2: TT, ACA, ATTA. So the answer will be 4. ) Use dynamic programming in O(n 2 ) steps. Half the credit goes for a clear definition of the variables you introduce (the brain of the algorithm, not to be confused with the recurrence, the heart of the algorithm). Pseudocode required. 11

13. (XC, 20 points) Let G = (V, E, w) be an undirected weighted graph and let A V be a nonempty proper subset of V (so A V ). The separation sep(a) is defined as sep(a) = min{w(a, b) a A, b V \ A}. Given G, find a subset A with maximum possible separation. Do this in linear time. Explain your algorithm in clear English. No pseudocode needed. Justify the running time. 12