1Solutions to Midterm 1. a. Using only definition of O(f(n)) prove that the following statement is true: 2n2/(log n + 1) = O(n2) b. Using only definition of O(f(n)) prove that the following statement is false: 2n2+1 = O(n) a)We claim that 2n2/(log n + 1) ≤cn2 where c = 2, n ≥1. Proof: For n≥1 we have log n + 1 ≥1 which implies 1/(log n + 1) ≤1, i.e. n2/(log n + 1) ≤n2 b) 2n2+1 = O(n) means that there is a constant c and n0such that for all n≥n0, 2n2+1≤cn. But if n≥c then 2n2+1 ≥2cn+1> cn, a contradiction. 2. 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
This is the end of the preview. Sign up
access the rest of the document.
Big O notation, Computational complexity theory, Worst-case complexity