1. Engineering
  2. Computer Science
  3. algorithms question answer carefully and completely for a thumbs up...

Question: algorithms question answer carefully and completely for a thumbs up...

Question details

Algorithms Question

Answer carefully and completely for a thumbs up

Question 1 The two algorithms presented below solve the element uniqueness problem. They verify whether all elements in a given array are distinct ALGORITHM uniqueElements1 (A[O. .n-1]) // Input: an array A[0..n-1] of real numbers Output: true if all elements in A are distinct and false otherwise for i<-0 to n-2 do for j-it1 to n-1 do if A[i] A[j] return false return true ALGORITHM uniqueElements2 (A[O. .n-1]) /7 Solves the element uniqueness problem by sorting the array first // Input: an array AIO..n-1] of real numbers // Output: true if all elements in A are distinct and false otherwise Sort the array A using merge-sort for i-0 to n-2 do if A[ǐ1-=A [i+1] return false return true (a) Trace algorithm uniqueElements1 for the array of n-6 numbers 5, 7, 9, 3, 9,14 What does the algorithm return? (b) Explain how algorithms uniqueElements1 and uniqueElements2 operate and why they succeed in solving the element uniqueness problem (c) What is the worst-case input for uniqueElements1? (d) What is the running time of uniqueElements1 in terms of big-Oh? In order to provide a full justification, explain what the main operation is, how many times it is repeated and then use the formal definition of big-Oh (e) Analyse the running time of algorithm uniqueElements2. Make sure you take into account the running time of the sorting step as we are interested in the overall time complexity of uniqueElements2 (there is no need to analyse merge-sort, just state its running time)

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution