Comparing every something to every other something is an N^2 operation. But, in this case, our something is already O(N^2), so the final algorithm is actually O(N^4).
If you are just checking for equality, comparing each of N items to another group of N items is O(N). Use a hash table.
If you are just checking for equality, comparing each of N items to another group of N items is O(N). Use a hash table.