Peter Nied What is the runtime of a contains call on java's Set.of() collection?
The runtime of a contains call on Java's Set.of() collection is O(1) on average, assuming a well-distributed hash function for the objects being stored in the set.
This is because Set.of() returns an immutable set implementation that uses a hash table to store its elements. When contains is called on the set, the hash table is used to quickly locate the element being searched for based on its hash code. Since hash table lookup has an average time complexity of O(1), the contains operation also has an average time complexity of O(1).
However, it's important to note that the worst-case time complexity of contains on a hash set can be O(n), where n is the number of elements in the set. This can occur if there are hash collisions and all elements in the set have the same hash code, in which case the hash table degrades to a linked list and the contains operation becomes a linear search through the list. However, the probabilit