S
S
sionzenit2012-12-25 09:06:57
Java
sionzenit, 2012-12-25 09:06:57

Search for maximally suitable sets

Good morning everyone!
I am new to Java. Faced such task:
There is result = Set[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
And there are many other Sets
A = Set[1, 2, 3, 4, 5, 6, 7, 8]
B = Set[1, 2, 3, 4, 5]
C = Set[1, 2, 3 , 4, 5, 6]
D = Set[1, 2, 3, 4, 5, 6, 7]
E = Set[9]
F = Set[10]
J = Set[9, 10
] covering sets, i.e. as a result, I have to return only the sets A and J.
Tell me in which direction to dig? I think that here it is somehow possible to resolve this matter using containsAll() and size(), but maybe there is already some kind of ready-made solution or algorithm?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Brand, 2012-12-25
@sionzenit

en.wikipedia.org/wiki/Set_cover_problem

M
metar, 2012-12-25
@metar

The search for the minimum vertex cover is a typical NP-complete problem, so you can:
a) boldly write an exhaustive search and optimize the search until you get bored;
b) get inspired here - this is an efficient iteration algorithm for a problem that finds all vertices, except for those that will be in the answer to your problem. :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question