What's a good algorithm for searching arrays N and M, in order to find elements in N that also exist

Posted by GenTiradentes on Stack Overflow See other posts from Stack Overflow or by GenTiradentes
Published on 2010-06-11T19:19:55Z Indexed on 2010/06/11 19:22 UTC
Read the original article Hit count: 216

Filed under:
|
|
|
|

I have two arrays, N and M. they are both arbitrarily sized, though N is usually smaller than M. I want to find out what elements in N also exist in M, in the fastest way possible.

To give you an example of one possible instance of the program, N is an array 12 units in size, and M is an array 1,000 units in size. I want to find which elements in N also exist in M. (There may not be any matches.) The more parallel the solution, the better.

I used to use a hash map for this, but it's not quite as efficient as I'd like it to be.

Typing this out, I just thought of running a binary search of M on sizeof(N) independent threads. (Using CUDA) I'll see how this works, though other suggestions are welcome.

© Stack Overflow or respective owner

Related posts about search

Related posts about binary