Data structure for matching sets

前端 未结 13 1129
有刺的猬
有刺的猬 2021-02-02 00:14

I have an application where I have a number of sets. A set might be
{4, 7, 12, 18}
unique numbers and all less than 50.

I then have several data items:
1 {1,

13条回答
  •  独厮守ぢ
    2021-02-02 00:38

    If you're going to improve performance, you're going to have to do something fancy to reduce the number of set comparisons you make.

    Maybe you can partition the data items so that you have all those where 1 is the smallest element in one group, and all those where 2 is the smallest item in another group, and so on.

    When it comes to searching, you find the smallest value in the search set, and look at the group where that value is present.

    Or, perhaps, group them into 50 groups by 'this data item contains N' for N = 1..50.

    When it comes to searching, you find the size of each group that holds each element of the set, and then search just the smallest group.

    The concern with this - especially the latter - is that the overhead of reducing the search time might outweigh the performance benefit from the reduced search space.

提交回复
热议问题