q2-f2007-sol

q2-f2007-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 November 28, 2007 Massachusetts Institute of Technology 6.006 Fall 2007 Professors Ron Rivest and Srini Devadas Quiz 2 Solutions Quiz 2 Solutions Problem 1. True/False [25 points] (5 parts) Decide whether each statement below is True or False . You must justify all your answers to receive full credit. (a) There exists a comparison sort of 5 numbers that uses at most 6 comparisons in the worst case. True False Explain: Solution: False. The number of leaves of a decision tree which sorts 5 numbers is 5! and the height of the tree is at least lg(5!) . Since 5! = 120 , 2 6 = 64 , and 2 7 = 128 , we have 6 < lg(5!) < 7 . Thus at least 7 comparisons are required. (b) Heapsort can be used as the auxiliary sorting routine in radix sort, because it operates in place. True False Explain: Solution: False. The auxiliary sorting routine in radix sort needs to be stable, mean- ing that numbers with the same value appear in the output array in the same order as they do appear in the input array. Heapsort is not stable. It does operate in place, meaning that only a constant number of elements of the input array are ever stored outside the array.
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 Quiz 2 Solutions Name 2 (c) If the DFS finishing time f [ u ] > f [ v ] for two vertices u and v in a directed graph G , and u and v are in the same DFS tree in the DFS forest, then u is an ancestor of v in the depth first tree. True False Explain: Solution: False. In a graph with three nodes, r u and v , with edges ( r,u ) and ( r,v ) , and r is the starting point for the DFS, u and v are siblings in the DFS tree, neither as the ancestor of the other. (d) The sequence h 20 , 15 , 18 , 7 , 9 , 5 , 12 , 3 , 6 , 2 i is a max-heap. True False Explain: Solution: True. For every node with 1-based index i > 1 , the node with index b i 2 c is larger.
Background image of page 2
6.006 Quiz 2 Solutions Name 3 (e) Let P be a shortest path from some vertex s to some other vertex t in a graph. If the weight of each edge in the graph is increased by one, P will still be a shortest path from s to t .
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 / 10

q2-f2007-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