Question: Describe an efficient algorithm that, given an unsorted array A[1..n], counts the number of distinct elements in A, i.e., only counts each element once
Describe an efficient algorithm that, given an unsorted array A[1..n], counts the number of distinct elements in A, i.e., only counts each element once no matter how many times it appears. You can use algorithms we have looked at in class with their correctness and time analysis without further explanation. (a) (3 points) Which algorithms from class are you using? For each, give the time complexity from class. (b) (5 points) Clearly describe your algorithm using the above as sub-routines. (c) (3 points) Explain why the algorithm above correctly counts the number of distinct elements. This does not require a full proof, but should be clear and unambiguous. (d) (9 points). Give a time analysis of your algorithm, referring to the time analysis of the sub- routines. (3 points correct analysis, 3 points explanation of time analysis, 3 points efficiency. Your algorithm must take time O(n) to get any points for efficiency.) G
Step by Step Solution
3.41 Rating (145 Votes )
There are 3 Steps involved in it
a Algorithms Used and Their Time Complexities Merge Sort Time complexity is On log n Linear Search T... View full answer
Get step-by-step solutions from verified subject matter experts
