Yesterday I was pairing the socks from the clean laundry and figured out the way I was doing it is not very efficient. I was doing a naive search — picking one sock and
The theoretical limit is O(n) because you need to touch each sock (unless some are already paired somehow).
You can achieve O(n) with radix sort. You just need to pick some attributes for the buckets.
If you can pick a limited number of attributes, but enough attributes that can uniquely identify each pair, you should be done in O(k * n), which is O(n) if we can consider k is limited.