I have a set of nodes that each contain 0 or more points. There are duplicate points between nodes, but each node may contain points that are unique to that node.
For example:
- Node A
- Point 1
- Point 2
- Point 3
- Node B
- Node C
- Point 1
- Point 4
- Node D
- Point 2
etc.
Is there an algorithm or method to find the fewest number of nodes that would contain the most number of points, up to a specific limit?
In the above example, if I needed 4 unique points, I would get Node A and Node C, OR Node A and Node D.
Presently, I am solving this problem by sorting the list of nodes in descending order by the number of points (so Node A, Node C, Node D) and discarding nodes that have no points (Node B). I am then iterating over that list of nodes, counting unique points (and recording what Nodes are looked at), until I hit a defined threshold of unique points. So, in the above example, my result would be Node A and Node C.
For what it's worth, I'm doing this in Javascript, but I think my question is more a "how to solve the problem" and not related to a specific language. Apologies if this is the incorrect place to post.