4
$\begingroup$

Lately, I asked this question to find the maximal set of elements $S$ of a given array $T$ such that every element of $S$ is greater than or equal to the cardinality of $S$.

My question is now different. How to find all maximal sets $S_i$ of a given array $T$ such that every element of $S_i$ is greater than or equal to the cardinality of $S_i$.

For example, if $T=[9, 8, 2, 2, 1],ドル then all maximal sets that satisfy the condition are $S_1=[9, 8],ドル $S_2=[9, 2],ドル $S_3=[9, 2],ドル $S_4=[8, 2],ドル $S_5=[8, 2]$ and $S_6=[2, 2]$.

My recursive solution or the solutions given in the previous question do not generate all maximal sets.

Is there any efficient algorithm that finds all maximal sets of such problem?

I think one way to solve the problem is to find a maximal set $S$ and return its size $|S|$--using any algorithm from this question. Then, generate all combinations $\displaystyle\binom{|T|}{|S|}$ and find which one of these combinations satisfies the condition. But can we do better?

asked Nov 18, 2016 at 18:53
$\endgroup$
2
  • 1
    $\begingroup$ Obviously, you can drop 1 from T, once you know that |S|=2. Other than that (and some duplicate handling), there is nothing to improve. There really are that many maximal sets. $\endgroup$ Commented Nov 18, 2016 at 19:34
  • 1
    $\begingroup$ What do you mean by maximal set? Maximum size, or inclusion-maximal? $\endgroup$ Commented Nov 18, 2016 at 21:07

1 Answer 1

4
$\begingroup$

Assuming that by maximal sets you mean sets of maximal size (rather than sets which are inclusion-maximal), then there is a very simple algorithm. First, find the maximal size $s$. Second, filter out all elements smaller than $s$. Third, output all subsets of size $s$ of the remaining elements.

answered Nov 18, 2016 at 21:10
$\endgroup$
1
  • $\begingroup$ Good. I think this works fine. Thanks. $\endgroup$ Commented Nov 18, 2016 at 21:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.