I have two large sets of integers $A$ and $B$. Each set has about a million entries, and each entry is a positive integer that is at most 10 digits long.
What is the best algorithm to compute $A\setminus B$ and $B\setminus A$? or inIn other words How, how can I efficiently compute the list of entries of A$A$ that are not in B$B$ and vice-versa versa? What would be the best datastructuredata structure to represent these two sets, to make these operations efficient?
The best approach I can come up with is storing these two sets as sorted lists, and compare everyevery element of A$A$ against every element of B$B$, in a linear fashion. Can we do it better?