final-s2009-sol

final-s2009-sol - Introduction to Algorithms Massachusetts...

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

View Full Document Right Arrow Icon
Introduction to Algorithms May 21, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Final Exam Solutions Final Exam Solutions Problem 1. True or False [24 points] (8 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 There exists an algorithm to build a binary search tree from an unsorted list in O ( n ) time. Explain: Solution: False. Because an in-order walk can create a sorted list from a BST in O ( n ) time, the existence of such an algorithm would violate the Ω( n lg n ) lower bound on comparison-based sorts. (b) T F There exists an algorithm to build a binary heap from an unsorted list in O ( n ) time. Explain: Solution: True. The standard BUILD - HEAP algorithm runs in O ( n ) time. (c) T F To solve the SSSP problem for a graph with no negative-weight edges, it is nec- essary that some edge be relaxed at least twice. Explain: Solution: False. Dijkstra’s algorithm solves the SSSP problem relaxing each edge at most once. (d) T F On a connected, directed graph with only positive edge weights, Bellman-Ford runs asymptotically as fast as Dijkstra. Explain: Solution: False. Bellman-Ford requires Θ( V E ) , regardless of the edge weights. Dijkstra runs in Θ( E + V lg V ) . Because the graph is connected, E = Ω( V ) , so Θ( V E ) = Ω( V 2 ) , which is clearly worse than Dijkstra.
Background image of page 1

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

View Full DocumentRight Arrow Icon
6.006 Final Exam Solutions Name 2 (e) T F A Givens rotation requires O (1) time. Explain: Solution: False. It may take O (1) time if the matrix is sparse, but in general a Givens rotation requires O ( n ) for a matrix with n columns. (f) T F In the worst case, merge sort runs in O ( n 2 ) time. Explain: Solution: True. Merge sort runs in O ( n lg n ) time which is O ( n 2 ) . (g) T F There exists a stable implementation of merge sort. Explain: Solution: True. If the items in the two lists being merged are equal, choose the item in the “left” half (the half that came first in the original array). (h) T F An AVL tree T contains n integers, all distinct. For a given integer k , there exists a Θ(lg n ) algorithm to find the element x in T such that | k - x | is minimized. Explain: Solution: True. I NSERT k , then find the P REDECESSOR and S UCCESSOR of k . Return the one whose difference with k is smaller. All three methods take Θ(lg n ) time.
Background image of page 2
6.006 Final Exam Solutions Name 3 Problem 2. Short Answer [32 points] (4 parts) (a) The eccentricity ǫ ( u ) of a vertex u in a connected, undirected, unweighted graph G is the maximum distance from u to any other vertex in the graph. That is, if δ ( u, v ) is the shortest path from u to v , then ǫ ( u ) = max v V δ ( u, v ) .
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/20/2012 for the course CS 6.006 taught by Professor Erikdemaine during the Fall '08 term at MIT.

Page1 / 12

final-s2009-sol - Introduction to Algorithms Massachusetts...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online