{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

q2-f2009-sol

# q2-f2009-sol - Introduction to Algorithms Massachusetts...

This preview shows pages 1–4. Sign up to view the full content.

Introduction to Algorithms November 18, 2009 Massachusetts Institute of Technology 6.006 Fall 2009 Professors Srini Devadas and Constantinos (Costis) Daskalakis Quiz 2 Solutions Quiz 2 Solutions Problem 1. True or False [14 points] (14 parts) For each of the following questions, circle either T (True) or F (False). (a) T F Heapsort is not a stable sorting algorithm. Solution: True (b) T F Finding the minimum element of a binary min heap takes logarithmic time. Solution: False (c) T F Any type of sorting algorithm can be used to sort the digits in one phase of radix sort. Solution: False (d) T F Given a matrix representation of a graph with V vertices, we can run depth-first search in O(V) time. Solution: False (e) T F DFS finds the longest paths from start vertex s to each vertex v in the graph. Solution: False (f) T F In a graph with negative weight cycles, one such cycle can be found in O ( V E ) time where V is the number of vertices and E is the number of edges in the graph. Solution: True (g) T F One always obtains the shortest path to each vertex, i.e., one using the minimum number of edges, using breadth-first search. Solution: True

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6.006 Quiz 2 Solutions Name 2 (h) T F A directed graph with a negative weight cycle has a topological ordering. Solution: False (i) T F If one can reach every vertex from a start vertex in a directed graph, then the graph is strongly connected. Solution: False (j) T F Topological sort can be performed using one breadth-first search procedure on the graph. Solution: False (k) T F Finding the strongly connected components in a graph requires Ω( V E ) time where V is the number of vertices and E is the number of edges. Solution: False (l) T F If one transforms edge weights w ( u, v ) to w ( u, v ) = w ( u, v ) - λ ( u ) + λ ( v ) for arbitrary λ () , then Dijkstra on the modified graph will return shortest paths in the original graph. Solution: False (m) T F The only operations required by Dijkstra on the priority queue data structure are EXTRACT MIN, INSERT and DECREASE KEY. Solution: True (n) T F Dijkstra assumes the triangle inequality on edge weights, that is, for each triple of edges ( u, v ) , ( u, a ) and ( a, v ) , we have w ( u, v ) > = w ( u, a ) + w ( a, v ) . Solution: False
6.006 Quiz 2 Solutions Name 3 Problem 2. Merging Multiple Lists [15 points] You are given K sorted lists of numbers. Each list has length N/K , so the total length of all of the lists is N . Describe an algorithm using heaps to merge these K lists of N/K numbers into a single sorted list of N numbers. Your algorithm should run in O ( N log K ) time, although you will receive partial credit for less efficient algorithms.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}