I'm working in an algorithm and one of the steps requires me to check whether or not 2 sequences of integers are what I call 'compatible' this is, their intersection is empty. I managed to make this intersection procedure O(n) but I was wondering if there was a way to make it even faster.
The sequences I have look like this:
<0 1 2 3 4 8>, <2 3 4 5 9> so these two sequences wouldn't be compatible because their intersection <2 3 4> is not empty.
I do not REQUIRE to perform the intersection procedure, this is just the way I came up with to know whether or not they share an integer.
I tried assigning each sequence a number such as the sum of the squares of all integers in the sequence:
For sequence $<x_1,x_2,x_3>$ this approach would assign $x_1^2+x_2^2+x^3_3$, then I'd say that if the assigned integer of sequence $s_1$ is equal to the assigned integer of sequence $s_2$ then $s_1$ and $s_2$ have an integer in common, but this is not the case in general.
I do not need to know which integer they share in common, I just need to know whether they share one(or more) or not. Any ideas?
Thanks for your time!