final-f2008-sol

# final-f2008-sol - Introduction to Algorithms December 15,...

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 Document

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.

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 NP-hard. Explain: Solution: True. SAT is NP-complete. This follows from the definitions of NP-hard and NP-complete. (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 COUNTING-SORT that sorts a set of n (unrestricted) integers in linear time. The algorithm works the same as COUNTING-SORT, 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 comparison-based 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 in-order 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 max-heap can support both the INCREASE-KEY and DECREASE-KEY 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.

### Page1 / 14

final-f2008-sol - Introduction to Algorithms December 15,...

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

View Full Document
Ask a homework question - tutors are online