Quantcast
Channel: What is the time complexity performance of HashSet.contains() in Java? - Stack Overflow
Browsing latest articles
Browse All 6 View Live

Answer by Daniel Valland for What is the time complexity performance of...

The worst-case performance of contains will be O(log n) for Java 8, and O(n) for Java 7, but average case closer to O(1). This is because the hashset is backed by a hashmap, and thus has the same...

View Article



Answer by Eran for What is the time complexity performance of...

It runs in O(1) expected time, as any hash table (assuming the hash function is decent). It is backed by a HashMap where the key is the Object. Two objects might have the same hash code, but the...

View Article

What is the time complexity performance of HashSet.contains() in Java?

I'm tempted to think that the HashSet.contains(Object) method performs in constant time. It simply gets the hash code of an object and then looks it up in a hash table.First, could someone please...

View Article
Browsing latest articles
Browse All 6 View Live




Latest Images