quiz2solns - CMPS 10 Quiz 2 Fall 2007 Solutions 1. (6...

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

View Full Document Right Arrow Icon
CMPS 10 Fall 2007 Quiz 2 Solutions 1. (6 Points) Suppose algorithms A and B solve the same problem. On input of size n , algorithm A does 2 15 n basic operations, while algorithm B does 3 ) 05 (. n basic operations. a. (2 Points) Which of the two algorithms is most efficient for large n ? Answer: A is most efficient for large n b. (2 Points) For what value of n are the two algorithms equally efficient? Solution: 3 2 ) 05 (. 15 n n = ) 05 /(. 15 = n 300 = n c. (2 Points) How many basic operations would be performed by either algorithm on input of the size n you found in part (b)? Solution: 000 , 350 , 1 ) 300 ( 15 2 = basic operations 2. (8 Points) Trace the following algorithm. 1) 1 i 2) while 6 i 3) 1 j 4) while i j 5) print ‘happy’ 6) 1 + j j 7) 1 + i i 8) stop Determine the number of times line 5 is executed. In other words, determine the number of times the word ‘happy’ will be printed. Solution:
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2011 for the course CMPS 10 taught by Professor Tantalo during the Fall '08 term at University of California, Santa Cruz.

Page1 / 2

quiz2solns - CMPS 10 Quiz 2 Fall 2007 Solutions 1. (6...

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

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