2c03-review - 00023

2c03-review - 00023 - Solutions to Midterm 1.[10] a.[5]...

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

View Full Document Right Arrow Icon
1 Solutions to Midterm 1.[10] a.[5] Using only definition of O(f(n)) prove that the following statement is true: 2n 2 /(log n + 1) = O(n 2 ) b.[5] Using only definition of O(f(n)) prove that the following statement is false: 2n 2 +1 = O(n) a) We claim that 2n 2 /(log n + 1) cn 2 where c = 2, n 1. Proof: For n 1 we have log n + 1 1 which implies 1/(log n + 1) 1, i.e. n 2 /(log n + 1) n 2 b) 2n 2 +1 = O(n) means that there is a constant c and n 0 such that for all n n 0 , 2n 2 +1 cn. But if n c then 2n 2 +1 2cn+1> cn, a contradiction. 2.[10] Write a procedure (in pseudo code) ERASE_DUPLICANTS(L) to erase all the repetitions of all the elements of L. For instance if L = a,b,c,a,a,b,a the result of ERASE_DUPLICANTS(L) should be a, b, c. Assume that L is implemented as a singly
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.
Ask a homework question - tutors are online