Reputation: 193
There is an ArrayList
of 10000+ items. I am trying to make them unique through a HashSet
which is a operation of O(n) complexity. Is there any other algorithm / DS which can make a Collection
unique with lower complexity than O(n)?
Upvotes: 2
Views: 498
Reputation: 39
Without going through all the elements once, it is not possible to confirm that your set has all unique values. Hence, O(n) is minimum possible.
Upvotes: 1
Reputation: 198471
No, this is literally impossible. O(n) is the minimum complexity to so much as read through the ArrayList
, let alone do anything with the elements.
Upvotes: 7