Describe and analyze an efficient algorithm for removing all
Describe and analyze an efficient algorithm for removing all duplicates from a collection of n elements. You may assume that the ordering of the elements does matter.
Solution
Answer:
Sort the Collection A of n elements.
this can be effortlessly done by merge sort or Quick Sort in O(nlogn) time.
After that store all the different element into another array.
This can be done by placing a single condition in a loop that
if(element_array[i] != element_array[i+1]) then store element_array[i] in output array.
Since this takes O(n) time.
so, total time = O(nlogn). {Very efficient method}
