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

Size: px
Start display at page:

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

Transcription

1 University of New Mexico Department of Computer Science Final Examination CS 362 Data Structures and Algorithms Spring, 2007 Name: Print your name and , neatly in the space provided above; print your name at the upper right corner of every page. Please print legibly. This is an closed book exam. You are permitted to use only two pages of cheat sheets that you have brought to the exam and a calculator. Nothing else is permitted. Do all the problems in this booklet. Show your work! You will not get partial credit if we cannot figure out how you arrived at your answer. Write your answers in the space provided for the corresponding problem. Let us know if you need more paper. Don t spend too much time on any single problem. The questions are weighted equally. If you get stuck, move on to something else and come back later. If any question is unclear, ask us for clarification. Question Points Score Grader Total 100

2 1. Short Answer (a) Consider the greedy algorithm for activity selection discussed in class. If there is some activity that has finish time earlier than the start time of all other activities, will this activity always be selected by the greedy algorithm? Justify your answer. Solution: Yes the activity will always be selected since it conflicts with no other activities. (b) Is the minimum weight edge in a graph always in any minimum spanning tree for a graph? Is it always in any single source shortest path tree for the graph? Justify your answers. Solution: The minimum weight edge is always in the MST for the graph. You can see this by noting that this edge is always included by Kruskal s algorithm. The minimum weight edge need not be in a single source shortest path (SSSP) tree. Consider the graph consisting of nodes a,b,c where w(a,b) = 2, w(a,c) = 2, w(b,c)=1. Then the SSSP tree rooted at a consists of the edges (a,b) and (a,c)

3 (c) Assume you have an implementation of the Union-Find data structure that has an amortized cost of Θ(log n) for all operations (note that this is a suboptimal implementation of Union-Find). If you use this data structure to implement Kruskal s algorithm on a connected graph with n nodes and m edges, what will be the run time of Kruskal s? Explain your answer. Solution: It will still take O(m log m) time since sorting the edges will still be the bottleneck for the algorithm. (d) Consider the problem 3-SAT discussed in class. If someone proves that this problem can be solved in polynomial time, what are the implications for the complexity classes P and NP? If someone shows that the problem can not be solved in polynomial time, what does this imply about P and NP? What would it imply about all the NP-Hard problems? Solution: If someone shows that SAT can be solved in polynomial time, then this means that P = NP. If someone shows that 3-SAT can not be solved in polynomial time, it implies that P NP and indeed that all the NP-Hard problems are not in P. This is the case since if we could solve any NP-Hard problem in polynomial time, we can solve 3-SAT in polynomial time.

4 2. Recurrences and Asymptotics (a) Give an asymptotic solution for the following recurrence: T (n) = 4T (n/2) + 1 Solution: f(n) = 1 and af(n/b) = 4 so f(n) c af(n/b) for c > 1. Thus the leaf nodes dominate and so T (n) = Θ(4 log 2 n ) = Θ(n 2 ) (b) Solve the following recurrence T (n) = 3T (n 1)+4T (n 2). Give the solution in general form i.e. do not solve for the constants Solution: The annihilator is L 2 3L 4 which factors to (L 4)(L+1). This implies that the general solution is T (n) = c 1 (4) n +c 2 ( 1) n

5 (c) Assume the run time of some algorithm is given by the recurrence T (n) = 2T ( n)+log n. What is the asymptotic run time of this algorithm? Solution: We need to do a transformation. Let n = 2 i. Then we have that T (2 i ) = 2T (2 i/2 ) + i. Now let t(i) = T (2 i ). Then we have t(i) = 2t(i/2) + i. But this is easy to solve, it s just the recurrence for mergesort. So we know that t(i) = i log i. This implies that T (2 i ) = i log i. This implies that T (n) = log n(log log n). (d) Prove that log n = o(log 2 n). Solution: Goal: Want to show that for all positive constants c, there exists a n 0 such that log n < c log 2 n for all n n 0. The inequality we want then is: log n c log 2 n 1 c log n 1/c log n Thus we need to choose n 0 such that log n 0 1/c.

6 3. P and NP Consider the following problem which is based on a real-world problem occurring in computational biology. We want to build a representative set for a large collection of protein molecules that we don t understand. The idea is to intensively study the proteins in the representative set and thereby learn something about all the proteins in the large collection. To be useful, the representative set must have the following two properties: it must be small so it s not too expensive to study it; and every protein in the collection must either be in the representative set or all proteins similar to it must be in the representative set. Thus the representative set problem can be defined as follows. You are given a large set S of proteins and you are also given a list L of all pairs of proteins that are similar to each other. Your goal is to find a subset S of S such that 1) every protein p in S is either in S or all proteins similar to p are in S and 2) S is the smallest subset with this property. What is the difficulty of the representative set problem? I.e. is it NP-Hard or is it in P? If it s NP-Hard, show this is the case and describe how you might approximate it. If it s in P, give a polynomial time algorithm to solve the problem. Solution: The problem is NP-Hard - it can be made equivalent to vertex cover as follows. Let each protein be a node in a graph G and let there be an edge between two nodes in the graph if their corresponding proteins are similar. Now let Z be the set of all nodes of degree zero and let G be G with the nodes Z removed. The vertex cover for G plus all nodes Z is the representative set. To see this, note that the requirement that each node either be in S or have all its neighbors in S is equivalent to all zero degree nodes being in the representative set and all edges in the graph having one vertex in the representative set. Note that we need to remove all vertices of degree 0 to make the problem equivalent to vertex cover - we took off points on this problem if this critical change was not stated. Since vertex cover is NP-Hard, so is this problem. Moreover, we can approximate vertex cover by using the greedy 2-approximation algorithm described in class. This gives us a 2-approximation algorithm for the representative set problem since all the zero degree vertices must be in the optimal solution.

7 4. Trees The minimum bottleneck spanning tree (MBST) is a spanning tree that seeks to minimize the most expensive edge in the tree. More specifically, for a tree T over a graph G, we say that e is a bottleneck edge of T if it s an edge with maximal cost. The, the tree T is a minimum bottleneck spanning tree if T is a spanning tree and there is no other spanning tree of G with a cheaper bottleneck edge. (a) Assume you are given a graph G and a weight w and that G has n nodes and m edges. Give a simple O(n + m) time algorithm that determines if there is a MBST with bottleneck edge with cost no more than w. Solution: Remove all edges with cost more than w from the graph. Then run DFS on the graph starting at an arbitrary vertex to determine if there is a tree on the remaining edges that spans all the nodes. (b) Is a MBST for a graph G always a minimum spanning tree for G? If so, prove it. If not, give a counter example. Solution: The answer is no. Consider a graph over 4 vertices a,b,c,d, with the following weight function over the edges. w(a,b) = 1, w(b,c) = 2, w(c,d) = 3, w(a,c) = 2. Then (a,c), (b,c), (c,d) is a MBST but it is not a minimum spanning tree since (a,b), (b,c), (c,d) has minimum total cost.

8 (c) Is a minimum spanning tree for a graph G always a MBST for G? If so, prove it. If not, give a counter example. Hint: Use the safe edge theorem. Solution: The answer is yes. Let T be a MST for G and assume by way of contradiction that T is not a MBST. Then there must be some edge e = (x, y) that is more costly than the minimum cost bandwidth edge. But then consider a cut that respects T e and thus has x on one side and y on the other. There must then be some edge e with weight less than e that crosses this cut. Why? Because we know that the MBST uses edges with weight less than e and we know the MBST must have one edge that crosses this cut. Finally consider the tree T which is T with e removed and e added. T is a spanning tree and it has less total weight than T. But this contradicts our assumption that T is a MST. Thus, if T is a MST, T is also a MBST.

9 5. Summer Fishing Note: This problem is similar to a job interview question asked at Facebook.com. After your hard work during the year at UNM, you want to take a long deserved fishing break this summer. However, you want to plan your fishing trip so that you catch as many fish as possible and have thus formulated the following problem. You have a map of the fishing spots of New Mexico which you represent as a graph G. Each node in G is a fishing spot and two nodes x and y are connected if and only if it s possible to travel from x to y in an evening (after a day of fishing). Let n be the number of nodes in this graph. Your fishing trip will last for l days and you ve created a n by l prediction matrix c, based on your uncanny and infallible knowledge of fishing conditions, such that c(v, t) is the number of fish you will catch at spot v on day t. Note that for the same fishing spot v, and for different days t and t, c(v, t) may not equal c(v, t ) because of different weather conditions, and so forth. Your problem is the following. Design an algorithm that given a graph G, a start node s in G, and a matrix c, will plan a fishing trip that ensures you catch the maximum number of fish. In other words, your algorithm will return a path of l nodes, starting at s, and going through G such that this path ensures that the maximum number of fish will be caught from among all paths of length l. What is the runtime of your algorithm? Solution: This is a dynamic programming problem. For node v and day t, let m(v, t) be the maximum number of fish that can be caught in a trip that starts at s and ends after t days at node v. First we will define a recurrence for m. Base case: m(s, 1) = c(s, 1) and for all v s, m(v, 1) = (this is to enforce the fact that we must start at node s). Recurrence: For 1 < t l, m(v, t) = c(v, t) + max v N(v)m(v, t), where N(v) is the set of all neighbors of v in G. The value we want in the end is the maximum over all v of m(v, l). It s easy to transform this recurrence into a dynamic program. We just fill in the array m(v, t) for increasing values of t. This will require three nest loops and the total run time of the algorithm will be O(n 2 l)

10 5. Summer Fishing, continued.

University of New Mexico Department of Computer Science. Midterm Examination. CS 361 Data Structures and Algorithms Spring, 2003

University of New Mexico Department of Computer Science. Midterm Examination. CS 361 Data Structures and Algorithms Spring, 2003 University of New Mexico Department of Computer Science Midterm Examination CS 361 Data Structures and Algorithms Spring, 2003 Name: Email: Print your name and email, neatly in the space provided above;

More information

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

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2006 University of New Mexico Department of Computer Science Final Examination CS 561 Data Structures and Algorithms Fall, 2006 Name: Email: Print your name and email, neatly in the space provided above; print

More information

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

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2013 University of New Mexico Department of Computer Science Final Examination CS 561 Data Structures and Algorithms Fall, 2013 Name: Email: This exam lasts 2 hours. It is closed book and closed notes wing

More information

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

CPSC 320 (Intermediate Algorithm Design and Analysis). Summer Instructor: Dr. Lior Malka Final Examination, July 24th, 2009 CPSC 320 (Intermediate Algorithm Design and Analysis). Summer 2009. Instructor: Dr. Lior Malka Final Examination, July 24th, 2009 Student ID: INSTRUCTIONS: There are 6 questions printed on pages 1 7. Exam

More information

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

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016 University of Toronto Department of Electrical and Computer Engineering Final Examination ECE 345 Algorithms and Data Structures Fall 2016 Print your first name, last name, UTORid, and student number neatly

More information

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016) 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

More information

Algorithm Design Strategies V

Algorithm Design Strategies V Algorithm Design Strategies V Joaquim Madeira Version 0.0 October 2016 U. Aveiro, October 2016 1 Overview The 0-1 Knapsack Problem Revisited The Fractional Knapsack Problem Greedy Algorithms Example Coin

More information

Final Exam Version A December 16, 2014 Name: NetID: Section: # Total Score

Final Exam Version A December 16, 2014 Name: NetID: Section: # Total Score CS 374 : Algorithms and Models of Computation, Fall 2014 Final Exam Version A December 16, 2014 Name: NetID: Section: 1 2 3 # 1 2 3 4 5 6 Total Score Max 20 10 10 10 10 10 70 Grader Don t panic! Please

More information

Final Exam (Version B) December 16, 2014 Name: NetID: Section: 1 2 3

Final Exam (Version B) December 16, 2014 Name: NetID: Section: 1 2 3 CS 374 : Algorithms and Models of Computation, Fall 2014 Final Exam (Version B) December 16, 2014 Name: NetID: Section: 1 2 3 # 1 2 3 4 5 6 Total Score Max 20 10 10 10 10 10 70 Grader Don t panic! Please

More information

CS 161: Design and Analysis of Algorithms

CS 161: Design and Analysis of Algorithms CS 161: Design and Analysis of Algorithms Greedy Algorithms 3: Minimum Spanning Trees/Scheduling Disjoint Sets, continued Analysis of Kruskal s Algorithm Interval Scheduling Disjoint Sets, Continued Each

More information

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013 /4/3 Administrative Big O David Kauchak cs3 Spring 3 l Assignment : how d it go? l Assignment : out soon l CLRS code? l Videos Insertion-sort Insertion-sort Does it terminate? /4/3 Insertion-sort Loop

More information

CS325: Analysis of Algorithms, Fall Final Exam

CS325: Analysis of Algorithms, Fall Final Exam CS: Analysis of Algorithms, Fall 0 Final Exam I don t know policy: you may write I don t know and nothing else to answer a question and receive percent of the total points for that problem whereas a completely

More information

CS/COE

CS/COE CS/COE 1501 www.cs.pitt.edu/~nlf4/cs1501/ P vs NP But first, something completely different... Some computational problems are unsolvable No algorithm can be written that will always produce the correct

More information

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012 University of Illinois at Chicago Department of Computer Science Final Examination CS 151 Mathematical Foundations of Computer Science Fall 01 Thursday, October 18, 01 Name: Email: Print your name and

More information

CS 170 Algorithms Fall 2014 David Wagner MT2

CS 170 Algorithms Fall 2014 David Wagner MT2 CS 170 Algorithms Fall 2014 David Wagner MT2 PRINT your name:, (last) SIGN your name: (first) Your Student ID number: Your Unix account login: cs170- The room you are sitting in right now: Name of the

More information

CS2223 Algorithms D Term 2009 Exam 3 Solutions

CS2223 Algorithms D Term 2009 Exam 3 Solutions CS2223 Algorithms D Term 2009 Exam 3 Solutions May 4, 2009 By Prof. Carolina Ruiz Dept. of Computer Science WPI PROBLEM 1: Asymptoptic Growth Rates (10 points) Let A and B be two algorithms with runtimes

More information

1 Primals and Duals: Zero Sum Games

1 Primals and Duals: Zero Sum Games CS 124 Section #11 Zero Sum Games; NP Completeness 4/15/17 1 Primals and Duals: Zero Sum Games We can represent various situations of conflict in life in terms of matrix games. For example, the game shown

More information

CS 170 Algorithms Spring 2009 David Wagner Final

CS 170 Algorithms Spring 2009 David Wagner Final CS 170 Algorithms Spring 2009 David Wagner Final PRINT your name:, (last) SIGN your name: (first) PRINT your Unix account login: Your TA s name: Name of the person sitting to your left: Name of the person

More information

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

NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: 2017 2018 Time Allowed 2 Hours INSTRUCTIONS TO STUDENTS 1. This assessment consists of Eight (8) questions and comprises

More information

MIDTERM Fundamental Algorithms, Spring 2008, Professor Yap March 10, 2008

MIDTERM Fundamental Algorithms, Spring 2008, Professor Yap March 10, 2008 INSTRUCTIONS: MIDTERM Fundamental Algorithms, Spring 2008, Professor Yap March 10, 2008 0. This is a closed book exam, with one 8 x11 (2-sided) cheat sheet. 1. Please answer ALL questions (there is ONE

More information

Today s Outline. CS 362, Lecture 4. Annihilator Method. Lookup Table. Annihilators for recurrences with non-homogeneous terms Transformations

Today s Outline. CS 362, Lecture 4. Annihilator Method. Lookup Table. Annihilators for recurrences with non-homogeneous terms Transformations Today s Outline CS 362, Lecture 4 Jared Saia University of New Mexico Annihilators for recurrences with non-homogeneous terms Transformations 1 Annihilator Method Lookup Table Write down the annihilator

More information

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

Contents Lecture 4. Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression Contents Lecture 4 Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression Jonas Skeppstedt (jonasskeppstedt.net) Lecture 4 2018

More information

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005 CSCE 750 Final Exam Answer Key Wednesday December 7, 2005 Do all problems. Put your answers on blank paper or in a test booklet. There are 00 points total in the exam. You have 80 minutes. Please note

More information

Algorithms Exam TIN093 /DIT602

Algorithms Exam TIN093 /DIT602 Algorithms Exam TIN093 /DIT602 Course: Algorithms Course code: TIN 093, TIN 092 (CTH), DIT 602 (GU) Date, time: 21st October 2017, 14:00 18:00 Building: SBM Responsible teacher: Peter Damaschke, Tel. 5405

More information

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

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3 Banner ID: Name: Midterm Exam CS 3110: Design and Analysis of Algorithms June 20, 2006 Group 1 Group 2 Group 3 Question 1.1 Question 2.1 Question 3.1 Question 1.2 Question 2.2 Question 3.2 Question 3.3

More information

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

Design and Analysis of Algorithms May 12, 2011 Massachusetts Institute of Technology. Practice Final Exam. Problem Title Points Parts Grade Initials Design and Analysis of Algorithms May 12, 2011 Massachusetts Institute of Technology 6.046J/18.410J Profs. Dana Moshkovitz and Bruce Tidor Practice Final Exam Practice Final Exam Do not open this quiz

More information

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

Class Note #20. In today s class, the following four concepts were introduced: decision Class Note #20 Date: 03/29/2006 [Overall Information] In today s class, the following four concepts were introduced: decision version of a problem, formal language, P and NP. We also discussed the relationship

More information

CMPSCI611: The Matroid Theorem Lecture 5

CMPSCI611: The Matroid Theorem Lecture 5 CMPSCI611: The Matroid Theorem Lecture 5 We first review our definitions: A subset system is a set E together with a set of subsets of E, called I, such that I is closed under inclusion. This means that

More information

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

Design and Analysis of Algorithms April 16, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 2 Design and Analysis of Algorithms April 16, 2015 Massachusetts Institute of Technology 6.046J/18.410J Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 2 Quiz 2 Do not open this quiz booklet until

More information

Final Exam, Machine Learning, Spring 2009

Final Exam, Machine Learning, Spring 2009 Name: Andrew ID: Final Exam, 10701 Machine Learning, Spring 2009 - The exam is open-book, open-notes, no electronics other than calculators. - The maximum possible score on this exam is 100. You have 3

More information

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

University of California Berkeley CS170: Efficient Algorithms and Intractable Problems November 19, 2001 Professor Luca Trevisan. Midterm 2 Solutions University of California Berkeley Handout MS2 CS170: Efficient Algorithms and Intractable Problems November 19, 2001 Professor Luca Trevisan Midterm 2 Solutions Problem 1. Provide the following information:

More information

Lecture 18: P & NP. Revised, May 1, CLRS, pp

Lecture 18: P & NP. Revised, May 1, CLRS, pp Lecture 18: P & NP Revised, May 1, 2003 CLRS, pp.966-982 The course so far: techniques for designing efficient algorithms, e.g., divide-and-conquer, dynamic-programming, greedy-algorithms. What happens

More information

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

CMPSCI 311: Introduction to Algorithms Second Midterm Exam CMPSCI 311: Introduction to Algorithms Second Midterm Exam April 11, 2018. Name: ID: Instructions: Answer the questions directly on the exam pages. Show all your work for each question. Providing more

More information

Math 391: Midterm 1.0 Spring 2016

Math 391: Midterm 1.0 Spring 2016 Math 391: Midterm 1.0 Spring 2016 James Skon skonjp@kenyon.edu Test date: October 5 Submission Instructions: Give all your assumptions. Show all your work. Be as complete as possible. Grading Problem 1

More information

ICS 252 Introduction to Computer Design

ICS 252 Introduction to Computer Design ICS 252 fall 2006 Eli Bozorgzadeh Computer Science Department-UCI References and Copyright Textbooks referred [Mic94] G. De Micheli Synthesis and Optimization of Digital Circuits McGraw-Hill, 1994. [CLR90]

More information

COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017

COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017 NAME: COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017 A. McGregor 15 November 2017 DIRECTIONS: Do not turn over the page until you are told to do so. This is a closed book exam. No communicating

More information

Exam EDAF August Thore Husfeldt

Exam EDAF August Thore Husfeldt Exam EDAF05 25 August 2011 Thore Husfeldt Instructions What to bring. You can bring any written aid you want. This includes the course book and a dictionary. In fact, these two things are the only aids

More information

COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017

COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017 NAME: COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017 A. McGregor 15 November 2017 DIRECTIONS: Do not turn over the page until you are told to do so. This is a closed book exam. No communicating

More information

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

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 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 } 5 else 6 j = 2n+ alg(n 1) 7 return j } } Set up a recurrence relation

More information

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

University of Washington March 21, 2013 Department of Computer Science and Engineering CSEP 521, Winter Exam Solution, Monday, March 18, 2013 University of Washington March 21, 2013 Department of Computer Science and Engineering CSEP 521, Winter 2013 Exam Solution, Monday, March 18, 2013 Instructions: NAME: Closed book, closed notes, no calculators

More information

HW8. Due: November 1, 2018

HW8. Due: November 1, 2018 CSCI 1010 Theory of Computation HW8 Due: November 1, 2018 Attach a fully filled-in cover sheet to the front of your printed homework Your name should not appear anywhere; the cover sheet and each individual

More information

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem? Admin Two more assignments No office hours on tomorrow NP-COMPLETE PROBLEMS Run-time analysis Tractable vs. intractable problems We ve spent a lot of time in this class putting algorithms into specific

More information

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

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts) Introduction to Algorithms October 13, 2010 Massachusetts Institute of Technology 6.006 Fall 2010 Professors Konstantinos Daskalakis and Patrick Jaillet Quiz 1 Solutions Quiz 1 Solutions Problem 1. We

More information

CS 361, Lecture 14. Outline

CS 361, Lecture 14. Outline Bucket Sort CS 361, Lecture 14 Jared Saia University of New Mexico Bucket sort assumes that the input is drawn from a uniform distribution over the range [0, 1) Basic idea is to divide the interval [0,

More information

P vs. NP. Data Structures and Algorithms CSE AU 1

P vs. NP. Data Structures and Algorithms CSE AU 1 P vs. NP Data Structures and Algorithms CSE 373-18AU 1 Goals for today Define P, NP, and NP-complete Explain the P vs. NP problem -why it s the biggest open problem in CS. -And what to do when a problem

More information

CSI 4105 MIDTERM SOLUTION

CSI 4105 MIDTERM SOLUTION University of Ottawa CSI 4105 MIDTERM SOLUTION Instructor: Lucia Moura Feb 6, 2010 10:00 am Duration: 1:50 hs Closed book Last name: First name: Student number: There are 4 questions and 100 marks total.

More information

CSE 421 Introduction to Algorithms Final Exam Winter 2005

CSE 421 Introduction to Algorithms Final Exam Winter 2005 NAME: CSE 421 Introduction to Algorithms Final Exam Winter 2005 P. Beame 14 March 2005 DIRECTIONS: Answer the problems on the exam paper. Open book. Open notes. If you need extra space use the back of

More information

Introduction to Algorithms March 10, 2010 Massachusetts Institute of Technology Spring 2010 Professors Piotr Indyk and David Karger Quiz 1

Introduction to Algorithms March 10, 2010 Massachusetts Institute of Technology Spring 2010 Professors Piotr Indyk and David Karger Quiz 1 Introduction to Algorithms March 10, 2010 Massachusetts Institute of Technology 6.006 Spring 2010 Professors Piotr Indyk and David Karger Quiz 1 Quiz 1 Do not open this quiz booklet until directed to do

More information

Written Homework #1: Analysis of Algorithms

Written Homework #1: Analysis of Algorithms Written Homework #1: Analysis of Algorithms CIS 121 Fall 2016 cis121-16fa-staff@googlegroups.com Due: Thursday, September 15th, 2015 before 10:30am (You must submit your homework online via Canvas. A paper

More information

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

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees , 2009 Lecture 5: Shortest Paths & Spanning Trees University of Twente m.uetz@utwente.nl wwwhome.math.utwente.nl/~uetzm/dw/ Shortest Path Problem "#$%&'%()*%"()$#+,&- Given directed "#$%&'()*+,%+('-*.#/'01234564'.*,'7+"-%/8',&'5"4'84%#3

More information

P, NP, NP-Complete. Ruth Anderson

P, NP, NP-Complete. Ruth Anderson P, NP, NP-Complete Ruth Anderson A Few Problems: Euler Circuits Hamiltonian Circuits Intractability: P and NP NP-Complete What now? Today s Agenda 2 Try it! Which of these can you draw (trace all edges)

More information

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

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science ALGORITHMS FOR INFERENCE Fall 2014 MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.438 ALGORITHMS FOR INFERENCE Fall 2014 Quiz 2 Wednesday, December 10, 2014 7:00pm 10:00pm This is a closed

More information

Methods for solving recurrences

Methods for solving recurrences Methods for solving recurrences Analyzing the complexity of mergesort The merge function Consider the following implementation: 1 int merge ( int v1, int n1, int v, int n ) { 3 int r = malloc ( ( n1+n

More information

NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt):

NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt): CS 170 First Midterm 26 Feb 2010 NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt): Instructions: This is a closed book, closed calculator,

More information

Dominating Set. Chapter 7

Dominating Set. Chapter 7 Chapter 7 Dominating Set In this chapter we present another randomized algorithm that demonstrates the power of randomization to break symmetries. We study the problem of finding a small dominating set

More information

CS325: Analysis of Algorithms, Fall Midterm

CS325: Analysis of Algorithms, Fall Midterm CS325: Analysis of Algorithms, Fall 2017 Midterm I don t know policy: you may write I don t know and nothing else to answer a question and receive 25 percent of the total points for that problem whereas

More information

COT 6936: Topics in Algorithms! Giri Narasimhan. ECS 254A / EC 2443; Phone: x3748

COT 6936: Topics in Algorithms! Giri Narasimhan. ECS 254A / EC 2443; Phone: x3748 COT 6936: Topics in Algorithms! Giri Narasimhan ECS 254A / EC 2443; Phone: x3748 giri@cs.fiu.edu https://moodle.cis.fiu.edu/v2.1/course/view.php?id=612 Gaussian Elimination! Solving a system of simultaneous

More information

CSCI 3110 Assignment 6 Solutions

CSCI 3110 Assignment 6 Solutions CSCI 3110 Assignment 6 Solutions December 5, 2012 2.4 (4 pts) Suppose you are choosing between the following three algorithms: 1. Algorithm A solves problems by dividing them into five subproblems of half

More information

1. Problem I calculated these out by hand. It was tedious, but kind of fun, in a a computer should really be doing this sort of way.

1. Problem I calculated these out by hand. It was tedious, but kind of fun, in a a computer should really be doing this sort of way. . Problem 5.2-. I calculated these out by hand. It was tedious, but kind of fun, in a a computer should really be doing this sort of way. 2 655 95 45 243 77 33 33 93 86 5 36 8 3 5 2 4 2 2 2 4 2 2 4 4 2

More information

Midterm 2. DO NOT turn this page until you are instructed to do so

Midterm 2. DO NOT turn this page until you are instructed to do so University of California Berkeley Handout M2 CS170: Efficient Algorithms and Intractable Problems November 15, 2001 Professor Luca Trevisan Midterm 2 DO NOT turn this page until you are instructed to do

More information

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch] NP-Completeness Andreas Klappenecker [based on slides by Prof. Welch] 1 Prelude: Informal Discussion (Incidentally, we will never get very formal in this course) 2 Polynomial Time Algorithms Most of the

More information

VIII. NP-completeness

VIII. NP-completeness VIII. NP-completeness 1 / 15 NP-Completeness Overview 1. Introduction 2. P and NP 3. NP-complete (NPC): formal definition 4. How to prove a problem is NPC 5. How to solve a NPC problem: approximate algorithms

More information

Question Paper Code :

Question Paper Code : www.vidyarthiplus.com Reg. No. : B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2011. Time : Three hours Fourth Semester Computer Science and Engineering CS 2251 DESIGN AND ANALYSIS OF ALGORITHMS (Regulation

More information

How many hours would you estimate that you spent on this assignment?

How many hours would you estimate that you spent on this assignment? The first page of your homework submission must be a cover sheet answering the following questions. Do not leave it until the last minute; it s fine to fill out the cover sheet before you have completely

More information

Lecture 4: NP and computational intractability

Lecture 4: NP and computational intractability Chapter 4 Lecture 4: NP and computational intractability Listen to: Find the longest path, Daniel Barret What do we do today: polynomial time reduction NP, co-np and NP complete problems some examples

More information

Midterm 1 for CS 170

Midterm 1 for CS 170 UC Berkeley CS 170 Midterm 1 Lecturer: Satish Rao October 2 Midterm 1 for CS 170 Print your name:, (last) (first) Sign your name: Write your section number (e.g., 101): Write your SID: One page of notes

More information

An analogy from Calculus: limits

An analogy from Calculus: limits COMP 250 Fall 2018 35 - big O Nov. 30, 2018 We have seen several algorithms in the course, and we have loosely characterized their runtimes in terms of the size n of the input. We say that the algorithm

More information

Shortest Path Algorithms

Shortest Path Algorithms Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Single Source Shortest Path 2 Single Source Shortest Path Given: a directed or undirected graph G = (V,E) a source node

More information

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

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Limitations of Algorithms We conclude with a discussion of the limitations of the power of algorithms. That is, what kinds

More information

CS60007 Algorithm Design and Analysis 2018 Assignment 1

CS60007 Algorithm Design and Analysis 2018 Assignment 1 CS60007 Algorithm Design and Analysis 2018 Assignment 1 Palash Dey and Swagato Sanyal Indian Institute of Technology, Kharagpur Please submit the solutions of the problems 6, 11, 12 and 13 (written in

More information

1 Some loose ends from last time

1 Some loose ends from last time Cornell University, Fall 2010 CS 6820: Algorithms Lecture notes: Kruskal s and Borůvka s MST algorithms September 20, 2010 1 Some loose ends from last time 1.1 A lemma concerning greedy algorithms and

More information

Greedy Algorithms My T. UF

Greedy Algorithms My T. UF Introduction to Algorithms Greedy Algorithms @ UF Overview A greedy algorithm always makes the choice that looks best at the moment Make a locally optimal choice in hope of getting a globally optimal solution

More information

Exam EDAF May 2011, , Vic1. Thore Husfeldt

Exam EDAF May 2011, , Vic1. Thore Husfeldt Exam EDAF05 25 May 2011, 8.00 13.00, Vic1 Thore Husfeldt Instructions What to bring. You can bring any written aid you want. This includes the course book and a dictionary. In fact, these two things are

More information

Fall 2016 Test 1 with Solutions

Fall 2016 Test 1 with Solutions CS3510 Design & Analysis of Algorithms Fall 16 Section B Fall 2016 Test 1 with Solutions Instructor: Richard Peng In class, Friday, Sep 9, 2016 Do not open this quiz booklet until you are directed to do

More information

UNIVERSITY OF CALIFORNIA, RIVERSIDE

UNIVERSITY OF CALIFORNIA, RIVERSIDE UNIVERSITY OF CALIFORNIA, RIVERSIDE DEPARTMENT OF COMPUTER SCIENCE 2006 DEPTH EXAMINATION IN THEORY OF OF COMPUTATION AND ALGORITHMS There are 10 problems on the test. Each problem is worth 10 points.

More information

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

IS 709/809: Computational Methods in IS Research Fall Exam Review IS 709/809: Computational Methods in IS Research Fall 2017 Exam Review Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Exam When: Tuesday (11/28) 7:10pm

More information

Exam EDAF May Thore Husfeldt

Exam EDAF May Thore Husfeldt Exam EDAF05 29 May 13 Thore Husfeldt Instructions What to bring. You can bring any written aid you want. This includes the course book and a dictionary. In fact, these two things are the only aids that

More information

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

NP-Completeness. Until now we have been designing algorithms for specific problems NP-Completeness 1 Introduction Until now we have been designing algorithms for specific problems We have seen running times O(log n), O(n), O(n log n), O(n 2 ), O(n 3 )... We have also discussed lower

More information

Topics in Approximation Algorithms Solution for Homework 3

Topics in Approximation Algorithms Solution for Homework 3 Topics in Approximation Algorithms Solution for Homework 3 Problem 1 We show that any solution {U t } can be modified to satisfy U τ L τ as follows. Suppose U τ L τ, so there is a vertex v U τ but v L

More information

CS781 Lecture 3 January 27, 2011

CS781 Lecture 3 January 27, 2011 CS781 Lecture 3 January 7, 011 Greedy Algorithms Topics: Interval Scheduling and Partitioning Dijkstra s Shortest Path Algorithm Minimum Spanning Trees Single-Link k-clustering Interval Scheduling Interval

More information

The Traveling Salesman Problem: An Overview. David P. Williamson, Cornell University Ebay Research January 21, 2014

The Traveling Salesman Problem: An Overview. David P. Williamson, Cornell University Ebay Research January 21, 2014 The Traveling Salesman Problem: An Overview David P. Williamson, Cornell University Ebay Research January 21, 2014 (Cook 2012) A highly readable introduction Some terminology (imprecise) Problem Traditional

More information

NP-Complete Problems and Approximation Algorithms

NP-Complete Problems and Approximation Algorithms NP-Complete Problems and Approximation Algorithms Efficiency of Algorithms Algorithms that have time efficiency of O(n k ), that is polynomial of the input size, are considered to be tractable or easy

More information

CPSC 320 Sample Final Examination December 2013

CPSC 320 Sample Final Examination December 2013 CPSC 320 Sample Final Examination December 2013 [10] 1. Answer each of the following questions with true or false. Give a short justification for each of your answers. [5] a. 6 n O(5 n ) lim n + This is

More information

More on NP and Reductions

More on NP and Reductions Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 501 Advanced Data

More information

Hon.Algorithms (CSCI-GA 3520), Professor Yap Fall 2012 MIDTERM EXAM. Oct 11, 2012 SOLUTION

Hon.Algorithms (CSCI-GA 3520), Professor Yap Fall 2012 MIDTERM EXAM. Oct 11, 2012 SOLUTION Hon.Algorithms (CSCI-GA 352), Professor Yap Fall 22 MIDTERM EXAM Oct, 22 SOLUTIONS Problem. ( Points) Consider the recurrence T(n) = 4T(n/2)+ n2 lgn. Reduce this to standard form and solve it to Θ-order.

More information

Limitations of Algorithm Power

Limitations of Algorithm Power Limitations of Algorithm Power Objectives We now move into the third and final major theme for this course. 1. Tools for analyzing algorithms. 2. Design strategies for designing algorithms. 3. Identifying

More information

Minimum spanning tree

Minimum spanning tree Minimum spanning tree Jean Cousty MorphoGraph and Imagery 2011 J. Cousty : MorphoGraph and Imagery 1/17 Outline of the lecture 1 Minimum spanning tree 2 Cut theorem for MST 3 Kruskal algorithm J. Cousty

More information

Data Structures in Java

Data Structures in Java Data Structures in Java Lecture 21: Introduction to NP-Completeness 12/9/2015 Daniel Bauer Algorithms and Problem Solving Purpose of algorithms: find solutions to problems. Data Structures provide ways

More information

Introduction to Computer Science and Programming for Astronomers

Introduction to Computer Science and Programming for Astronomers Introduction to Computer Science and Programming for Astronomers Lecture 8. István Szapudi Institute for Astronomy University of Hawaii March 7, 2018 Outline Reminder 1 Reminder 2 3 4 Reminder We have

More information

CS173 Lecture B, November 3, 2015

CS173 Lecture B, November 3, 2015 CS173 Lecture B, November 3, 2015 Tandy Warnow November 3, 2015 CS 173, Lecture B November 3, 2015 Tandy Warnow Announcements Examlet 7 is a take-home exam, and is due November 10, 11:05 AM, in class.

More information

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths Matroids Shortest Paths Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths Marc Uetz University of Twente m.uetz@utwente.nl Lecture 2: sheet 1 / 25 Marc Uetz Discrete Optimization Matroids

More information

Graph Theory and Optimization Computational Complexity (in brief)

Graph Theory and Optimization Computational Complexity (in brief) Graph Theory and Optimization Computational Complexity (in brief) Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR 7271, Sophia Antipolis, France September 2015 N. Nisse Graph Theory

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 Data Structures and Algorithms Chapter 3 1. Divide and conquer 2. Merge sort, repeated substitutions 3. Tiling 4. Recurrences Recurrences Running times of algorithms with recursive calls can be described

More information

Exam EDAF January 2012, , Sparta:A D. Thore Husfeldt

Exam EDAF January 2012, , Sparta:A D. Thore Husfeldt Exam EDAF05 10 January 2012, 8.00 13.00, Sparta:A D Thore Husfeldt Instructions What to bring. You can bring any written aid you want. This includes the course book and a dictionary. In fact, these two

More information

UC Berkeley, CS 174: Combinatorics and Discrete Probability (Fall 2008) Midterm 1. October 7, 2008

UC Berkeley, CS 174: Combinatorics and Discrete Probability (Fall 2008) Midterm 1. October 7, 2008 UC Berkeley, CS 74: Combinatorics and Discrete Probability (Fall 2008) Midterm Instructor: Prof. Yun S. Song October 7, 2008 Your Name : Student ID# : Read these instructions carefully:. This is a closed-book

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 5 Greedy Algorithms Interval Scheduling Interval Partitioning Guest lecturer: Martin Furer Review In a DFS tree of an undirected graph, can there be an edge (u,v)

More information

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm Outline 1 NP-Completeness Theory 2 Limitation of Computation 3 Examples 4 Decision Problems 5 Verification Algorithm 6 Non-Deterministic Algorithm 7 NP-Complete Problems c Hu Ding (Michigan State University)

More information

Linear Selection and Linear Sorting

Linear Selection and Linear Sorting Analysis of Algorithms Linear Selection and Linear Sorting If more than one question appears correct, choose the more specific answer, unless otherwise instructed. Concept: linear selection 1. Suppose

More information

Variable Elimination (VE) Barak Sternberg

Variable Elimination (VE) Barak Sternberg Variable Elimination (VE) Barak Sternberg Basic Ideas in VE Example 1: Let G be a Chain Bayesian Graph: X 1 X 2 X n 1 X n How would one compute P X n = k? Using the CPDs: P X 2 = x = x Val X1 P X 1 = x

More information

25. Minimum Spanning Trees

25. Minimum Spanning Trees 695 25. Minimum Spanning Trees Motivation, Greedy, Algorithm Kruskal, General Rules, ADT Union-Find, Algorithm Jarnik, Prim, Dijkstra, Fibonacci Heaps [Ottman/Widmayer, Kap. 9.6, 6.2, 6.1, Cormen et al,

More information