Algorithm to find if two sets intersect

后端 未结 7 1797
一向
一向 2021-01-01 23:22

Let\'s say I have two arrays:

int ArrayA[] = {5, 17, 150, 230, 285};

int ArrayB[] = {7, 11, 57, 110, 230, 250};

Both arrays a

7条回答
  •  北海茫月
    2021-01-02 00:04

    If one list is much much shorter than the other, binary search is the way to go. If the lists are of similar length and you're happy with O(m+n), a standard "merge" would work. There are fancier algorithms that are more flexible. One paper I've come across in my own searches is:

    http://www.cs.uwaterloo.ca/~ajsaling/papers/paper-spire.pdf

提交回复
热议问题