Question

1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark 1729 is O(1) b) 3 marks 2n2-4n -3 is O(n2) 2. [3 marks] Using the definition of Big-Oh, prove that 2n2(n 1) is not O(n2) 3. 6 marks Let f(n),g(n), h(n) be complexity functions. Using the definition of Big-Oh, prove the following two claims a) 3 marks Let k be a positive real constant and f(n) is O(g(n)), then k f(n) is O(g(n)) b) 3 marks] If f(n) is O(g(n) and g(n) is O(h(n)), then f(n) is O(h(n)). 4. 11 marks Consider the element distinctness problem: Given an array A storing n inte- gers, determine whether all the elements in the array are distinct or not. That is, if all the elements in A are unique, return true; return false if there is at least one duplicate element in A. Below four different problem instances are provided; elements bolded are duplicate elements 0 1 2 3 4 5 6 12312 3 4 false 0 1 2 3 4 5 41 22 6 8 false 0 1 2 3 true 0 1 2 3 45 6 7 true Design an algorithm that solves the element distinctness problem. a) [4 marks Write pseudocode for the algorithm b) Prove your algorithm is correct, do this by proving the two following parts: i marks] Show that the algorithm terminates in finite time ii) 2 marks Show that the algorithm always produces correct output e) 1 mark Explain what the worst case for the algorithm is. d) 3 marks Perform worst-case analysis to compute the time complexity of the algorithm. You must give the order of your complexity function using Big-Oh notation, and you must explain how you computed the time complexity

0 0
Add a comment Improve this question Transcribed image text
Answer #1
O(g(n)) = { f(n): there exist positive constants c and 
                  n0 such that 0 <= f(n) <= c*g(n) for 
                  all n >= n0}

1.

a) Clearly, for c = 1730 and n >= 1, we have

0 <= 1729 <= c

Hence, 1729 = O(1)

b) For c = 2 and n >= 0, we have

0 <= 2n2 - 4n - 3 <= c*n2

Hence, 2n2 - 4n - 3 = O(n2)

2. f(n) = 2n2(n - 1) = 2n3 - 2n2

There does not exist any positive integer c such that

0 <= f(n) <= c*n2 where n >= 0

Hecne, f(n) != O(n2)

3.

a) Given that f(n) = O(g(n))

=> 0 <= f(n) <= c*g(n) where c is a positive constant

=> 0 <= k*f(n) <= k*c*g(n)

=> 0 <= k*f(n) <= c1*g(n) where c1 = k*c

Clearly, k*f(n) = O(g(n))

b)

Given that f(n) = O(g(n))

=> 0 <= f(n) <= c1*g(n) where c1 is a positive constant ------> (1)

Given that g(n) = O(h(n))

=> 0 <= g(n) <= c2*h(n) where c2 is a positive constant ------> (2)

Combining 1 and 2, we get

0 <= f(n) <= c1*g(n) <= c1*c2*h(n)

or, 0 <= f(n) <= c1*c2*h(n)

=> 0 <= f(n) <= c3*h(n) where c3 = c1*C2

Hence, f(n) = O(h(n))

NOTE: As per HOMEWORKLIB POLICY, I am allowed to answer only 4 questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.

Add a comment
Know the answer?
Add Answer to:
1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT