q1-f2007-sol

q1-f2007-sol - October 17, 2007 6.006 Fall 2007 Quiz 1...

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

View Full Document Right Arrow Icon
Introduction to Algorithms October 17, 2007 Massachusetts Institute of Technology 6.006 Fall 2007 Professors Ron Rivest and Srini Devadas Quiz 1 Solutions Quiz 1 Solutions Problem 1. Asymptotic Notation [25 points] (5 parts) State whether each statement below is True or False . You must briefly justify all your answers to receive full credit. (a) If f ( n ) = Θ( g ( n )) and g ( n ) = Θ( h ( n )) , then h ( n ) = Θ( f ( n )) Solution: True. Θ is transitive. (b) If f ( n ) = O ( g ( n )) and g ( n ) = O ( h ( n )) , then h ( n ) = Ω( f ( n )) Solution: True. O is transitive, and h ( n ) = Ω( f ( n )) is the same as f ( n ) = O ( h ( n )) (c) If f ( n ) = O ( g ( n )) and g ( n ) = O ( f ( n )) then f ( n ) = g ( n ) Solution: False: f ( n ) = n and g ( n ) = n + 1 . (d) n 100 = Ω( n ) Solution: True. n 100 < c * n for c = 1 200 .
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 (e) f ( n ) = Θ( n 2 ) , where f ( n ) is defined to be the running time of the program A(n) : def A(n): atuple = tuple(range(0, n)) # a tuple is an immutable version of a # list, so we can hash it S = set() for i in range(0, n): for j in range(i+1, n): S.add(atuple[i:j]) # add tuple (i,. ..,j-1) to set S Solution: False: Inside the two for loops, both slicing and hashing take linear time.
Background image of page 2
6.006 Quiz 1 Solutions Name 3 Problem 2. Weight-Balanced Binary Search Trees [20 points] (2 parts) Recall from class our definition of a weight-balanced binary search tree : it maintains the weight balance of each node x , such that if the weight of x is w ( x ) , the weight of each child is at least α · w ( x ) , where α = 0 . 29 . (The weight of x is one more than the number of nodes in the subtree rooted at x .) This property is maintained when a node is inserted by performing rotations and
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.

Page1 / 6

q1-f2007-sol - October 17, 2007 6.006 Fall 2007 Quiz 1...

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