solutions1

solutions1 - MIT OpenCourseWare http:/ocw.mit.edu 6.006...

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

View Full Document Right Arrow Icon
MIT OpenCourseWare http://ocw.mit.edu 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .
Background image of page 1

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms: 6.006 Massachusetts Institute of Technology March 7, 2008 Professors Srini Devadas and Erik Demaine Handout 6 Quiz 1 Practice Problems 1 Asymptotic Notation Decide whether these statements are True or False . You must briefly justify all your answers to receive full credit. 1. If f ( n ) = Θ( g ( n )) and g ( n ) = Θ( h ( n )) , then h ( n ) = Θ( f ( n )) Solution: True. Θ is transitive.± 2. 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 )) 3. 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 n 4. = Ω( n ) 100 Solution: True. n < c n for c = 1 . 100 200
Background image of page 2
2 Handout 6: Quiz 1 Practice Problems 5. 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. 2 Linked List Equivalence Let S and T be two sets of numbers, represented as unordered linked lists of distinct numbers. All you have are pointers to the heads of the lists, but you do not know the list lengths . Describe an O (min {| S | , | T |} ) -expected-time algorithm to determine whether S = T . You may assume that any operation on one or two numbers can be performed in constant time. Solution:
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 / 7

solutions1 - MIT OpenCourseWare http:/ocw.mit.edu 6.006...

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