Given two std::set
s, one can simply iterate through both sets simultaneously and compare the elements, resulting in linear complexity. This doesn\'t work for
The very worst case is O(n²).
But unordered sets are in fact ordered by hash. So it is possible to compare the hashes (if this fails the sets cannot be equal) and then verify that same hashes (linear) have real same values (O(n²) for different values with the same hash) behind.
In the best case this is O(n).
Normally the complexity tends to O(n) if the hash function is "good" (different objects -> always different hash) and to O(n²) if the hash function is "bad" (everything always has the same hash value)