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

Similar documents
Introduction to Algorithms November 28, 2007 Massachusetts Institute of Technology Fall 2007 Professors Ron Rivest and Srini Devadas Quiz 2

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

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

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

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

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

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.

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

6.006 Introduction to Algorithms Spring 2008

Quiz 2 Practice Problems

Introduction to Algorithms December 16, 2011 Massachusetts Institute of Technology Fall 2011 Professors Erik Demaine and Srini Devadas

Introduction to Algorithms March 12, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 1

Quiz 2 Solutions. (a) T F Topological sort requires Ω(V lg V ) if the edge weights are unbounded. Explain:

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

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Final Exam. Problem Parts Points Grade Grader Problem Parts Points Grade Grader Total 180. Name: Athena username: Joe WF3a. Joe WF2.

Homework Assignment #3 Graph

Graphs & Digraphs Tuesday, November 06, 2007

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.

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

U.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Satish Rao September 18, Midterm 1

Graph Algorithms (part 3 of CSC 282),

Graph Algorithms (part 3 of CSC 282),

Exam 3 Practice Problems

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

CSE 21 Summer 2017 Homework 4

Quiz 2 Solutions. [1 points] Write your name on top of each page.

Single Source Shortest Path

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

Unit 5F: Layout Compaction

Unit 3: Layout Compaction

U.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Umesh Vazirani February 13, Midterm 1

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

Algorithm Design and Analysis

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

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

Shortest Path Problem

Introduction to Algorithms. Lecture 11

Problem Pts Score Grader Problem Pts Score Grader

Graph. Vertex. edge. Directed Graph. Undirected Graph

Algorithms and Data Structures 2014 Exercises and Solutions Week 9

Minimum Spanning Trees

Final Exam Solutions

UCSD CSE 101 MIDTERM 1, Winter 2008

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

Algorithm Design, Anal. & Imp., Homework 4 Solution

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Prelim 2. CS 2110, April 26, 2016, 5:30 PM Total Question True/False Complexity Heaps Trees Graphs Max Score Grader

Dijkstra s Algorithm

Introduction to Algorithms: Massachusetts Institute of Technology November 1, 2011 Professors Erik Demaine and Srini Devadas Problem Set 6

CSE 373 Final Exam 3/14/06 Sample Solution

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

CS521 \ Notes for the Final Exam

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

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

Dijkstra s Shortest Path Algorithm

Prelim 2 Solution. CS 2110, April 26, 2016, 5:30 PM

Algorithm Design and Analysis

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 1st June 2017 Time: 14:00-16:00

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

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 27th January 2011 Time: 14:00-16:00

Problem Set 6 Solutions

15 210: Parallel and Sequential Data Structures and Algorithms

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Final Exam. COS 226 Algorithms and Data Structures Fall 2015

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

CS171 Final Practice Exam

Graph Algorithms. Definition

Shortest Paths. Nishant Mehta Lectures 10 and 11

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

Practical Session No. 12 Graphs, BFS, DFS, Topological sort

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

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

CSI 604 Elementary Graph Algorithms

Sample Solutions to Homework #4

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

TIE Graph algorithms

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

CS61BL. Lecture 5: Graphs Sorting

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

CS 310 Advanced Data Structures and Algorithms

: Principles of Automated Reasoning and Decision Making Midterm

CS 3410 Ch 14 Graphs and Paths

Graph Representation

COT 6405 Introduction to Theory of Algorithms

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Chapter 22. Elementary Graph Algorithms

CMPSCI 311: Introduction to Algorithms Practice Final Exam

CMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018

Undirected Graphs. Hwansoo Han

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

Lecture 11: Analysis of Algorithms (CS ) 1

Unit 2: Algorithmic Graph Theory

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

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

Graphs Data Structures

Single Source Shortest Paths

Transcription:

Introduction to Algorithms November 12, 2008 Massachusetts Institute of Technology 6.006 Fall 2008 Professors Ronald L. Rivest and Sivan Toledo Quiz 2 Quiz 2 Do not open this quiz booklet until directed to do so. Read all the instructions on this page. When the quiz begins, write your name on every page of this quiz booklet. You have 120 minutes to earn 120 points. Do not spend too much time on any one problem. Read them all through first, and attack them in the order that allows you to make the most progress. This quiz booklet contains 13 pages, including this one. Two extra sheets of scratch paper are attached. Please detach them before turning in your quiz at the end of the exam period. This quiz is closed book. You may use two 8 1 11 or A4 crib sheets (both sides). No 2 calculators or programmable devices are permitted. No cell phones or other communications devices are permitted. Write your solutions in the space provided. If you need more space, write on the back of the sheet containing the problem. Do not put part of the answer to one problem on the back of the sheet for another problem, since the pages may be separated for grading. Do not waste time and paper rederiving facts that we have studied. It is sufficient to cite known results. Show your work, as partial credit will be given. You will be graded not only on the correctness of your answer, but also on the clarity with which you express it. Be neat. Good luck! Problem Parts Points Grade Grader 1 2 10 2 10 30 3 3 20 4 2 20 5 3 20 6 3 20 Total 120 Name: Recitation: Christina 10 AM Christina 11 AM Jayant 12 PM Jayant 1 PM Jason 2 PM Matthew 3 PM

6.006 Quiz 2 Name 2 Problem 1. BFS/DFS [10 points] (2 parts) Give the visited node order for each type of graph search, starting with s, given the following adjacency lists and accompanying figure: adj(s) = [a, c, d], adj(a) = [ ], adj(c) = [e, b], adj(b) = [d], adj(d) = [c], adj(e) = [s]. d b s c a e (a) Breadth First Search (b) Depth First Search

6.006 Quiz 2 Name 3 Problem 2. Miscellaneous True/False [30 points] (10 parts) For each of the following questions, circle either T (True) or F (False). Explain your choice. (No credit if no explanation given.) (a) T F While running DFS on a directed graph, if from vertex u we visit a finished vertex v, then the edge (u, v) is a cross-edge. (b) T F Changing the RELAX function to update if d[v] d[u] + w(u, v) (instead of strictly greater than) may produce different shortest paths, but will not affect the correctness of the Bellman-Ford outputs d and π.

6.006 Quiz 2 Name 4 (c) T F The running time of Radix sort is effectively independent of whether the input is already sorted. (d) T F Let P be a shortest path from some vertex s to some other vertex t in a directed graph. If the weight of each edge in the graph is increased by one, P will still be a shortest path from s to t. (e) T F If a weighted directed graph G is known to have no shortest paths longer than k edges, then it suffices to run Bellman-Ford for only k passes in order to solve the single-source shortest paths problem on G.

6.006 Quiz 2 Name 5 (f) T F If a topological sort exists for the vertices in a directed graph, then a DFS on the graph will produce no back edges. (g) T F Dynamic programming is more closely related to BFS than it is to DFS. (h) T F A depth-first search of a directed graph always produces the same number of tree edges (i.e. independent of the order in which the vertices are provided and independent of the order of the adjacency lists).

6.006 Quiz 2 Name 6 (i) T F Suppose we do a DFS on a directed graph G. If we remove all of the back edges found, the resulting graph is now acyclic. (j) T F Both DFS and BFS require Ω(V ) storage for their operation. (That is, for working storage, above and beyond the storage needed to represent the input.)

6.006 Quiz 2 Name 7 Problem 3. Miscellaneous Short Answer [20 points] (3 parts) (a) Suppose you want to get from s to t on weighted graph G with nonnegative edge weights, but you would like to stop by u if it isn t too inconvenient. (Here too inconvenient means that it increases the length of your travel by more than 10%.) Describe an efficient algorithm that would determine an optimal s to t path given your preference for stopping at u along the way if not too inconvenient. It should either return the shortest path from s to t, or the shortest path from s to t containing u. (b) Explain how the rod-cutting problem described in class can still be solved by dynamic programming, even if cuts now cost $1 each. (In class, we assumed cuts were free.) Here is the pseudocode for the original solution, where the cuts were free: r = [0] * (n + 1) for k in range(1, n + 1): ans = p[k] for i range(1, k): ans = max(ans, p[i] + r[k - i]) r[k] = ans (It suffices to explain how to express r n, the maximum revenue achievable for a rod of size n, in terms of r 1, r 2,..., r n 1 and the prices p i that the market will pay for a piece of length i, for i = 1, 2,...n.)

6.006 Quiz 2 Name 8 (c) Suppose that you implement Dijkstra s algorithm using a priority queue algorithm that requires O(V ) time to initialize, worst-case f(v, E) time for each EXTRACT-MIN operation and worst-case g(v, E) time for each DECREASE-KEY operation. How much (worst-case) time does it take to run Dijkstra s algorithm on an input graph G = (V, E)?.

6.006 Quiz 2 Name 9 Problem 4. A Series of Tubes [20 points] (2 parts) Consider a network of computers represented by a directed graph G. Each vertex v V represents a computer, and each edge (u, v) E represents a network link from u to v. (a) Let each edge (u, v) in G have a weight w(u, v) (0, 1], representing the probability that a packet going from u to v is successfully delivered. Give an efficient algorithm to find the path along which a packet has the highest probability of reaching its destination (i.e., the path for which the product of the edge weights is maximized). Hint: Transform the weights and use a shortest path algorithm. (b) Now, instead of weighted edges, consider weighted vertices. In other words, network links never drop packets, but nodes might. Edges are not weighted, but each vertex v has a weight w(v) (0, 1], representing the probability that an incoming packet is not dropped by that node. Give an efficient algorithm to find the path along which a packet has the highest probability of reaching its destination (i.e., the path for which the product of the vertex weights is maximized). Hint: Transform the graph and use the algorithm from part (a).

6.006 Quiz 2 Name 10 Problem 5. Fast Flyer [20 points] (3 parts) You are given a list of all scheduled daily flights in the US, giving departure airports, departure times, destination airports, and arrival times. We want an algorithm to compute travel times between airports, including waiting times between connections. Assume that if one flight arrives at time t and another departs at time t t, travelers can make the connection. Further assume that at a given airport, no two events (arrivals or departures) occur at the same time, and that there are at most 100 events at any airport during a given day. All times are given in GMT; don t worry about time zones. Construct a weighted graph so that given a departure airport, a departure time T, and a destination airport, we can efficiently determine the earliest time T that a traveler can be guaranteed (according to the schedules!) of arriving at her destination on that day (ignore overnight flights and overnight airport stays). (a) What do vertices represent? What do edges in your graph represent, and what is the weight of an edge? (b) Give an upper bound on the number of edges and vertices in your graph if there are n airports in the US and m daily flights. Justify your bound.

6.006 Quiz 2 Name 11 (c) What algorithm would you use to compute the shortest travel times, and what is its running time in terms of the number of vertices, V, and the number of edges, E?

6.006 Quiz 2 Name 12 Problem 6. Articulation Points [20 points] (3 parts) We define an articulation point as a vertex that when removed causes a connected graph to become disconnected. For this problem, we will try to find the articulation points in an undirected graph G. (a) How can we efficiently check whether or not a graph is disconnected? (Hint: think of a recent problem set question) (b) Describe an algorithm that uses a brute force approach to find all the articulation points in G in O(V (V + E)) time.

6.006 Quiz 2 Name 13 An observer comments that the polynomial time algorithm is rather slow and suggests to use a linear time DFS approach instead. Let s explore this idea some more. (c) Suppose we run DFS on graph G. Consider the types of edges that can exist in a DFS tree produced from an undirected graph, recalling that cross edges can t happen in the DFS of an undirected graph. Argue that a non-root, non-leaf vertex u is an articulation point if and only if there exists a subtree rooted at a child of u that has no back edges to a proper ancestor of u. (FYI: The above idea can be extended to yield an O(V + E) algorithm to find all articulation points, but we don t have time for all of that on this quiz!)

SCRATCH PAPER

SCRATCH PAPER