Pairwise Set Intersection in Python

后端 未结 3 2014
南旧
南旧 2021-02-04 06:47

If I have a variable number of sets (let\'s call the number n), which have at most m elements each, what\'s the most efficient way to calculate the pairwise in

3条回答
  •  醉话见心
    2021-02-04 07:20

    If we can assume that the input sets are ordered, a pseudo-mergesort approach seems promising. Treating each set as a sorted stream, advance the streams in parallel, always only advancing those where the value is the lowest among all current iterators. Compare each current value with the new minimum every time an iterator is advanced, and dump the matches into your same-item collections.

提交回复
热议问题