Quiz4_sol - Solutions to Quiz 4 Question 1 proc...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solutions to Quiz 4 Question 1 proc mean(a_1,...,a_n: integers) m:=a_1 for i:=2 to n m:=m+a_i end for m:=m/n end proc {m is the mean} worst case: n operations. Question 2 (a) Is |2n2 - 7n| C|3n2 |, x > k for some k 1? Let k = 4, then both sides are always positive and definition is 2n2 - 7n 3Cn2 2n - 7 3Cn. For n = 4, 1 12C works for C = 1. So C = 1, k = 4 works. (b) We know 2n2 - 7n O(3n2 ). Show 2n2 - 7n (3n2 ) |2n2 - 7n| C|3n2 |, n > k. Set k = 4 and 2n - 7 3Cn, k > 4. For n = 4, 2 - 3C 7/4. So C = 1/12, k = 4 works. Thus 2n2 - 7n (3n2 ). (c) No. By defination, |7n| C|n2 |, n > k. Thus 7n Cn2 and then 7 Cn, which cannot be true for any C and k. Question 3 (a) n comparisons by the first "if". O(n). (b) First pass, (n - 1) comparisons. Second pass, (n - 2), ... Thus comparisons = n-1 k = (n-1)n . O(n2 ) k=1 2 1 ...
View Full Document

This note was uploaded on 06/07/2011 for the course COT 3100 taught by Professor Staff during the Summer '08 term at University of Florida.

Ask a homework question - tutors are online