This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Introduction to Algorithms December 15, 2008 Massachusetts Institute of Technology 6.006 Fall 2008 Professors Ronald L. Rivest and Sivan Toledo Final Examination Solutions Final Examination Solutions Problem 1. Miscellaneous True/False [18 points] (6 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 If the load factor of a hash table is less than 1, then there are no collisions. Explain: Solution: False. The table contains fewer elements than it has slots, but that doesn’t prevent elements from hashing to the same slot. (b) T F If SAT ≤ P A , then A is NPhard. Explain: Solution: True. SAT is NPcomplete. This follows from the definitions of NPhard and NPcomplete. (c) T F The longest common subsequence problem can be solved using an algorithm for finding the longest path in a weighted DAG. Explain: Solution: True. Shown in lecture. 6.006 Final Examination Solutions Name 2 (d) T F Applying a Givens rotation to a matrix changes at most one row of the matrix. Explain: Solution: False. It changes two rows. (e) T F The problem of finding the shortest path from s to t in a directed, weighted graph exhibits optimal substructure. Explain: Solution: True. The shortest path to t can be easily computed given the short est paths to all vertices from which there is an edge to t . (f) T F A single rotation is sufficient to restore the AVL invariant after an insertion into an AVL tree. Explain: Solution: False. Restoring the invariant may require Θ(lg n ) rotations. 6.006 Final Examination Solutions Name 3 Problem 2. More True/False [18 points] (6 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 Using hashing, we can create a sorting algorithm similar to COUNTINGSORT that sorts a set of n (unrestricted) integers in linear time. The algorithm works the same as COUNTINGSORT, except it uses the hash of each integer as the index into the counting sort table. Explain: Solution: False. Counting sort requires that the elements in its table are or dered according their indices into the table. Hashing the integers breaks this property (b) T F There exists a comparisonbased algorithm to construct a BST from an unordered list of n elements in O ( n ) time. Explain: Solution: False. Because we can create a sorted list from a BST in O ( n ) time via an inorder walk, this would violate the Ω( n lg n ) lower bound on comparison based sorting. (c) T F It is possible for a DFS on a directed graph with a positive number of edges to produce no tree edges. Explain: Solution: True. Consider a graph with two vertices, a and b , and a single edge ( a , b ). Starting the DFS at b produces no tree edges. (When the search then starts at a , the only edge is a cross edge.) 6.006 Final Examination Solutions Name 4 (d) T F A maxheap can support both the INCREASEKEY and DECREASEKEY opera...
View
Full
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.
 Fall '08
 ErikDemaine
 Algorithms

Click to edit the document details