q2-s2008-sol

q2-s2008-sol - Introduction to Algorithms Massachusetts...

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

Introduction to Algorithms April 16, 2008 Massachusetts Institute of Technology 6.006 Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2 Solutions Quiz 2 Solutions Problem 1. True or False [35 points] (7 parts) Decide whether these statements are True or False . You must brieﬂy justify all your answers to receive full credit. (a) To sort n integers in the range from 1 to n 2 , a good implementation of radix sort is asymptotically faster in the worst case than any comparison sort. True False Explain: Solution: True. Split each number into two digits, each between 0 and n . Then make two passes of counting sort, each taking θ ( n ) time. Any comparison sort will take Ω( n log n ) time. (b) Call an ordered pair ( x 1 ,y 1 ) of numbers lexically less than an ordered pair ( x 2 ,y 2 ) if either (i) x 1 < x 2 or (ii) x 1 = x 2 and y 1 < y 2 . Then a set of ordered pairs can be sorted lexically by two passes of a sorting algorithm that only compares individual numbers. True False Explain: Solution: True. The idea is similar to RADIX-SORT though it is not exactly the same. First we sort on the y i digit of each pair, ( x i ,y i ) . Next we sort on the x i digit using a stable sort.

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

View Full Document
6.006 Quiz 2 Solutions Name 2 (c) Any in-place sorting algorithm can be used as the auxiliary sort in radix sort. True False Explain: Solution: False. The auxiliary algorithm has to be stable . In-place means the algo- rithm only uses constant additional memory. (d) Every directed acyclic graph has only one topological ordering of its vertices. True False Explain: Solution: False. Counterexample: the graph { (1,2), (1,3) } can be topologically sorted either [1,2,3] or [1,3,2]. (e) If the priority queue in Dijkstra’s algorithm is implemented using a sorted linked list (where the list is kept sorted after each priority queue operation), then Dijkstra’s algo- rithm would run in O ( E lg V + V lg V ) time. True False Explain: Solution: False. The array can take Θ( V ) time to insert a node, and there are V nodes to insert, for a running time of Ω( V 2 ) . In addition, the Θ( E ) calls to decrease-key can each take Θ( V ) time for a total running time of Θ(( V + E ) V ) .
6.006 Quiz 2 Solutions Name 3 (f) In searching for a shortest path from vertex s to vertex t in a graph, two-way breadth- ﬁrst search never visits more nodes than a normal one-way breadth-ﬁrst search.

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.

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 / 11

q2-s2008-sol - Introduction to Algorithms Massachusetts...

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

View Full Document
Ask a homework question - tutors are online