q1-f2008-sol

q1-f2008-sol - October 15, 2008 6.006 Fall 2008 Quiz 1...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Algorithms October 15, 2008 Massachusetts Institute of Technology 6.006 Fall 2008 Professors Ronald L. Rivest and Sivan Toledo Quiz 1 Solutions Quiz 1 Solutions Problem 1. Asymptotic growth [10 points] For each pair of functions f ( n ) and g ( n ) given below: Write Θ in the box if f ( n ) = Θ( g ( n )) Write O in the box if f ( n ) = O ( g ( n )) Write Ω in the box if f ( n ) = Ω( g ( n )) Write X in the box if none of these relations holds If more than one such relation holds, write only the strongest one. No explanation needed. No partial credit. O , Θ , Ω or X f ( n ) g ( n ) O n 2 n 3 Ω n lg n n Θ 1 2 + sin n Ω 3 n 2 n Θ 4 n +4 2 2 n +2 O n lg n n 101 / 100 Θ lg 10 n lg n 3 O n ! ( n + 1)!
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 1 Solutions Name 2 Problem 2. Miscellaneous True/False [15 points] (5 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 A hash table guarantees constant lookup time. Explain: Solution: False. It only has expected constant lookup time; if Θ( n ) elements collide, then lookup may take Θ( n ) time in the worst case (assuming chaining). (b) T F A non-uniform hash function is expected to produce worse performance for a hash table than a uniform hash function. Explain: Solution: True. A non-uniform hash function is more likely to result in colli- sions, which leads to slower lookup times. (c) T F If every node in a binary tree has either 0 or 2 children, then the height of the tree is Θ(lg n ) . Explain: Solution: False. One counterexample is a tree like the one shown here, extending down and to the right. It has Θ( n ) height. (d) T F A heap A has each key randomly increased or decreased by 1. The random choices are independent. We can restore the heap property on A in linear time. Explain: Solution: True. Simply call B UILD -H EAP at the root, which runs in Θ( n ) time. (e) T F An AVL tree is balanced, therefore a median of all elements in the tree is always at the root or one of its two children. Explain: Solution: False. An AVL tree doesn’t guarantee that the left and right subtrees will be equal sizes; it only guarantees that the heights of the trees are close.
Background image of page 2
6.006 Quiz 1 Solutions Name 3 Problem 3. Sorting short answer [10 points] (3 parts) (a) What is the worst-case running time of insertion sort? How would you order the elements in the input array to achieve the worst case? Solution: Reverse order. Θ( n 2 ) running time. (b) Name a sorting algorithm that operates in-place and in Θ( n log n ) time. Solution: Heapsort. (c) Write down the recurrence relation for the running time of merge sort. (You don’t need to solve it.) Solution: T ( n ) = 2 T ( n 2 ) + Θ( n )
Background image of page 3

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

View Full DocumentRight Arrow Icon
6.006 Quiz 1 Solutions Name 4 Problem 4. Hashing [10 points] (4 parts) Give a hash table that uses chaining to handle collisions, how would using sorted python lists in
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

q1-f2008-sol - October 15, 2008 6.006 Fall 2008 Quiz 1...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online