I have two sets from Guava HashMultimap.values()
.
I need to find out if there's an intersection of these two non-empty sets with the best possible time complexity.
I don't need to know about the common elements, just if there's at least one common element.
I was thinking of using Sets.intersection()
, but it has time complexity O(m+n). Can we find out whether there's a common element without creating the entire intersection?
Something like (pseudocode):
set.intersection(set2).any()
The data set is pretty big and this operation happens within a loop, and hence performance is paramount.