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

Similar documents
CS 373: Combinatorial Algorithms, Spring 1999

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

END-TERM EXAMINATION

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

CS521 \ Notes for the Final Exam

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

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

Quiz 2. Problem Parts Points Grade Grader. Total 120. Name: Recitation: Jayant 12 PM. Christina 10 AM. Jayant 1 PM. Jason 2 PM.

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

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

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

Unit-5 Dynamic Programming 2016

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

Theorem 2.9: nearest addition algorithm

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

Notes for Lecture 24

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

Review of course COMP-251B winter 2010

Virtual University of Pakistan

CS270 Combinatorial Algorithms & Data Structures Spring Lecture 19:

COMP 355 Advanced Algorithms Approximation Algorithms: VC and TSP Chapter 11 (KT) Section (CLRS)

Question Points Score TOTAL 55 TOTAL (Calibrated) 50

Matching 4/21/2016. Bipartite Matching. 3330: Algorithms. First Try. Maximum Matching. Key Questions. Existence of Perfect Matching

Chapter 6. Dynamic Programming

Memoization/Dynamic Programming. The String reconstruction problem. CS124 Lecture 11 Spring 2018

Graph Contraction. Graph Contraction CSE341T/CSE549T 10/20/2014. Lecture 14

CMSC351 - Fall 2014, Final Exam

Introduction to Algorithms April 15, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 2

Module 6 NP-Complete Problems and Heuristics

Introduction to Algorithms November 17, 2011 Massachusetts Institute of Technology Fall 2011 Professors Erik Demaine and Srini Devadas Quiz 2

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.

Lecture 6 Basic Graph Algorithms

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

CS 161 Fall 2015 Final Exam

Dynamic Programming II

CS 373: Combinatorial Algorithms, Spring 1999

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

CS 350 Final Algorithms and Complexity. It is recommended that you read through the exam before you begin. Answer all questions in the space provided.

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

15CS43: DESIGN AND ANALYSIS OF ALGORITHMS

Chapter 9 Graph Algorithms

Homework 4 Solutions

Traveling Salesperson Problem (TSP)

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Approximation Algorithms

Final Exam May 8, 2018

Graph Algorithms (part 3 of CSC 282),

INSTITUTE OF AERONAUTICAL ENGINEERING

Midterm 2 March 10, 2014 Name: NetID: # Total Score

CSE 417 Branch & Bound (pt 4) Branch & Bound

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

Module 6 P, NP, NP-Complete Problems and Approximation Algorithms

Solving problems on graph algorithms

Module 6 NP-Complete Problems and Heuristics

Solutions to relevant spring 2000 exam problems

1 Variations of the Traveling Salesman Problem

Chapter 9 Graph Algorithms

SUGGESTION : read all the questions and their values before you start.

CSCE 350: Chin-Tser Huang. University of South Carolina

DESIGN AND ANALYSIS OF ALGORITHMS

Lecture 8: The Traveling Salesman Problem

CMSC 451: Lecture 22 Approximation Algorithms: Vertex Cover and TSP Tuesday, Dec 5, 2017

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V

1 The Traveling Salesman Problem

Shortest path problems

Final Exam Solutions

Approximation Algorithms

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

Questions? You are given the complete graph of Facebook. What questions would you ask? (What questions could we hope to answer?)

Dijkstra s algorithm for shortest paths when no edges have negative weight.

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

(a) Write code to do this without using any floating-point arithmetic. Efficiency is not a concern here.

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

All Shortest Paths. Questions from exercises and exams

1 The Traveling Salesman Problem

Ma/CS 6a Class 27: Shortest Paths

( ) n 3. n 2 ( ) D. Ο

Module 6 NP-Complete Problems and Heuristics

CS599: Convex and Combinatorial Optimization Fall 2013 Lecture 14: Combinatorial Problems as Linear Programs I. Instructor: Shaddin Dughmi

Analysis of Algorithms, I

APPROXIMATION ALGORITHMS FOR GEOMETRIC PROBLEMS

Graph Algorithms (part 3 of CSC 282),

Letter STUDENT NUMBER ALGORITHMICS (HESS) Written examination. Monday 31 October 2016

Exam Sample Questions CS3212: Algorithms and Data Structures

COS 226 Final Exam, Spring 2009

ECE250: Algorithms and Data Structures Final Review Course

Dynamic programming. Trivial problems are solved first More complex solutions are composed from the simpler solutions already computed

Algorithm Design and Analysis

Model Answer. Section A Q.1 - (20 1=10) B.Tech. (Fifth Semester) Examination Analysis and Design of Algorithm (IT3105N) (Information Technology)

PATH FINDING AND GRAPH TRAVERSAL

Assignment No 2 (Group B)

Ma/CS 6a Class 8: Eulerian Cycles

CS 561, Lecture 10. Jared Saia University of New Mexico

CS 4407 Algorithms. Lecture 8: Circumventing Intractability, using Approximation and other Techniques

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

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

CS61B, Fall 2015 Final Examination (with corrections) P. N. Hilfinger

CS 561, Lecture 10. Jared Saia University of New Mexico

Single Source Shortest Path (SSSP) Problem

Transcription:

University of New Mexico Department of Computer Science Final Examination CS 6 Data Structures and Algorithms Spring, 006 Name: Email: Print your name and email, 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 0 0 0 4 0 5 0 Total 00

. True or False True or False: (circle one, points each) (a) True or False: The greedy algorithm for fractional knapsack only takes a fractional amount of at most one item. Solution: True (b) True or False: If there is an activity with start time later than the finish time of all other activities, then the greedy algorithm for activity selection will always choose this activity.solution: True - this activity conflicts with no other activities so will always be chosen. (c) True or False: Let T be the shortest path tree rooted at x for some graph G. Then for any vertex y, the shortest path from x to y in G is the same as the path from x to y in T.Solution: True (d) True or False: Consider a graph G = (V, E), with negative weight edges. We can solve the single source shortest paths problem on G in O( V E ) time. Solution: True. Bellman-Ford takes O( V E ) time. (e) True or False: Consider a graph G = (V, E), with negative weight edges. The fastest time to determine if there is a negative cycle in G is O( V E ). Solution: True. We can do this with Bellman-Ford, taking O( V E ) time. (f) True or False: For a connected graph G, the BFS, DFS, MST and shortest path trees will all have the same number of edges. Solution: True. If G has n vertices, all spanning trees of G will have n edges. (g) True or False: Consider a graph G = (V, E), with negative weight edges. We can determine if G contains a negative cycle in O( V ) time. Solution: True. We can do this with Bellman-Ford, taking O( V ) time. (h) True or False: Consider an operation foo that has an amortized cost of. Then over n calls to foo, the worst case run time of a single call can be O(n). Solution: True (i) True or False: We know of a problem that is both in the class NP and in the class P. Solution: True. Any problem in NP is also in P. (j) True or False: The TSP approximation algorithm discussed in class finds a tour that has a cost within of optimal on all weighted graphs. Solution: False. It only guarantees a two approximation if the weights on the graph obey the triangle inequality.

. Short Answer (5 points each) Where appropriate, circle your final answer. (a) Solve the following recurrence using the master method: T (n) = T (n/) + n Solution: f(n) = n and af(n/b) = (/)n so f(n) c af(n/b) for c >. the root node dominates. Thus T (n) = Θ(n). Thus (b) Solve the following recurrence using annihilators: T (n) = T (n ) + T (n ). Give the solution in general form i.e. do not solve for the constants Solution: The annihilator is L L which factors to (L ( + 7)/)(L ( 7)/). This implies that the general solution is T (n) = c (( + 7)/) n + c (( 7)/) n

(c) Consider the problem CLIQUE discussed in class. If someone proves that P = NP, what can be said about this problem? If someone proves that P NP, what can be said about this problem? Solution: If P = NP, CLIQUE can be solved in polynomial time. If P NP, there is no polynomial time algorithm that can solve CLIQUE. (d) Prove that 00 n = O(n). Solution: Goal: Give positive constants c and n 0 such that 00 n cn for all n n 0. The inequality we want then is: 00 n cn 00/ n c The left hand side of this inequality is decreasing as n grows large. Thus if we choose n 0 = and c = 0, it satisfies the inequality for all n n 0. In other words, for c = 0 and n 0 =, it s the case that 00 n cn for all n n 0.

. Graph Theory Recall that in the Floyd-Warshall algorithm dist(u, v, r) is defined to be the shortest path from u to v where all intermediate vertices (if any) are numbered r or less. For the following graph, fill in the distance arrays computed by Floyd-Warshall for all values of r. In the distance arrays, let the row be the vertex the path starts at and let the column be the vertex the path ends at. - - r = 0 r = r = r =

r = 0 0-0 - 0 r = 0-0 - 0 Solution: r = 0-0 - 0 r = 0 - - 0-0

4. Spanning Trees (a) Assume you are given a connected graph G with n nodes and at least n edges. Give an algorithm to remove an edge from G without disconnecting the graph. Solution: You just need to find a spanning tree for G, using say DFS, and then remove an edge in G that is not in this spanning tree. (b) Consider the following traveling repairperson problem. There is a weighted, undirected graph G with all positive edge weights. The nodes of G represent cities and the weights on the edges represent distances between cities. There is a special vertex s in the graph. A traveling repairperson starts at the city s and wants to visit every node in the graph. However, the repairperson needs to travel back to the node s after visiting each city (to get new parts). Give an algorithm to find the shortest total route for the repairperson. Note that the repairperson is allowed to visit each city multiple times. Solution: The algorithm first finds a shortest path tree, T, rooted at s. The for each node v in the graph, the repair person first travels from s to v along the path given by T and the repair person then travels from v back to s along the same path. The total cost of this route is minimized since we are always taking shortest paths from s to each city, v.

5. NP-Hardness In your first job after taking CS6, you are presented with the following problem. There is a set of k machines at your company. There are n programs that need to be run on these machines where n > k. There is a list of conflicts: this is just a list of pairs of jobs, where each pair in the list represents two jobs that can not be run on the same machine. Your goal is to write a program that will assign each job to a single machine such that no two jobs that conflict are assigned to the same machine. (a) Which problem that we discussed in class is this problem equivalent to? Describe how it is equivalent. Solution: This problem is equivalent to the graph coloring problem. Each machine is a job. If two jobs conflict, there is an edge between the corresponding nodes. Assigning each job to one of the k machines is equivalent to finding a k-coloring for the graph. (b) What does this equivalence tell you about the likelihood of being able to successfully write an efficient program to solve this problem? Solution: Graph coloring is NP-Hard so unless P = NP, you will not be able to solve this problem in polynomial time.