final-s2008-sol-1

# final-s2008-sol-1 - Introduction to Algorithms May 21, 2008...

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 May 21, 2008 Massachusetts Institute of Technology 6.006 Spring 2008 Professors Srini Devadas and Erik Demaine Final Exam Solutions Final Exam Solutions Problem 1. Asymptotics [10 points] For each pair of functions f ( n ) and g ( n ) in the table below, write O , Ω , or Θ in the appropriate space, depending on whether f ( n ) = O ( g ( n )) , f ( n ) = Ω( g ( n )) , or f ( n ) = Θ( g ( n )) . If there is more than one relation between f ( n ) and g ( n ) , write only the strongest one. The first line is a demo solution. We use lg to denote the base-2 logarithm. Solution: n n lg n n 2 n lg 2 n Ω Ω O 2 lg 2 n Ω Ω Ω lg( n !) Ω Θ O n lg 3 Ω Ω O 6.006 Final Exam Solutions Name 2 Problem 2. True or False [40 points] (10 parts) Decide whether these statements are True or False . You must briefly justify all your answers to receive full credit. (a) An algorithm whose running time satisfies the recurrence P ( n ) = 1024 P ( n/ 2) + O ( n 100 ) is asymptotically faster than an algorithm whose running time satisfies the recurrence E ( n ) = 2 E ( n- 1024) + O (1) . True False Explain: Solution: True. The first recurrence leads to a result that is polynomial in n , while the second recurrence produces a result that is exponential in n . (b) An algorithm whose running time satisfies the recurrence A ( n ) = 4 A ( n/ 2) + O (1) is asymptotically faster than an algorithm whose running time satisfies the recurrence B ( n ) = 2 B ( n/ 4) + O (1) . True False Explain: Solution: False. Considering the recursion trees for A ( n ) and B ( n ) , it is easy to see that the tree for A has both a smaller height ( log 4 ( n ) vs. log 2 ( n ) ), and a smaller branching factor. 6.006 Final Exam Solutions Name 3 (c) Radix sort works in linear time only if the elements to sort are integers in the range { , 1 ,...,cn } for some c = O (1) . True False Explain: Solution: False. Radix sort also works in linear time if the elements to sort are integers in the range { 1 ,...,n d } for any constant d . (d) Given an undirected graph, it can be tested to determine whether or not it is a tree in O ( V + E ) time. A tree is a connected graph without any cycles. True False Explain: Solution: True. Using either DFS or BFS yields a running time of O ( V + E ) . 6.006 Final Exam Solutions Name 4 (e) The Bellman-Ford algorithm applies to instances of the single-source shortest path problem which do not have a negative-weight directed cycle, but it does not detect the existence of a negative-weight directed cycle if there is one. True False Explain: Solution: False. Bellman-Ford detects negative-weight directed cycles in its input graph. (f) The topological sort of an arbitrary directed acyclic graph G = ( V,E ) can be com- puted in linear time....
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 / 23

final-s2008-sol-1 - Introduction to Algorithms May 21, 2008...

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

View Full Document
Ask a homework question - tutors are online