[stackoverflow] [algorithm] Smashing sets together
Name:
Anonymous2015-02-17 20:46
Marxist feminist game developer Anita Leigh Goldbergstein is given N sets, e. g.:
★ <a, b> ★ <a, d> ★ <c> ★ <d, e> ★ <b, f, c>
She wants to merge them in such way that:
1⟩ resulting list of sets is the smallest possible, 2⟩ operations on sets that have non-null intersection (that is, if an element appears in both) are strictly forbidden.
What algorithm would you donate to her to solve this problem‽
Name:
Anonymous2015-02-18 6:35
Define a graph whose vertices are the sets, and put edges between each pair of sets that share an element. The problem is then to 'fold' this graph into the smallest number of vertices.
So for example, if your graph contains a triangle (<a,b>, <b,c>, <a,c>) you can't expect to get better than 3.
>>3 Yeah, it's edge coloring of a graph if the sets all have size 2.
Name:
Anonymous2015-02-18 7:01
letters are vertices, two element subsets are edges, and colors are unions of disjoint edges. Minimize colors.
Name:
Anonymous2015-02-18 8:19
>>8 The OP data has three-element sets, so unless you define something like "n-vertex edge" your approach makes no sense
Name:
Anonymous2015-02-18 8:33
>>9 >>7,8 show op's problem is at least as hard as edge coloring. >>3-kun actually described vertex coloring. Contracting two vertices together means you give them the same color. And since you can describe any graph with these sets, this problem is vertex coloring of arbitrary graphs. So, it's NP-hard.
Name:
Anonymous2015-02-18 8:40
DUBS CHECK'M
Name:
Anonymous2015-02-18 8:42
>>11 This one. This is the best algorithm in the thread.
Name:
Anonymous2015-02-18 8:46
I don't think Anita deserves better than brute force, construct all possible combinations and evaluate between them.
Name:
Anita Goldsteinman2015-02-18 17:53
>>2-13 Wow thank you /prog/, you surprised me with your math ability!
What algorithm would you donate to her to solve this problem‽
None. I wouldn't donate anything to a stupid Jewish cunt, as a matter of fact.
Name:
Anonymous2015-02-18 19:37
Actually no. There are 4 * 4 possible ways to transition from the OP's state to a smaller state. 4 * 4 / 2 actually because set union is commutative. From each of these, there are ceil(3 * 3 / 2). Etc. Therefore complexity of a bruteforce solution is n^4 (n^2 because obviously, another ^2 because each transition can involve any pair of sets)
Name:
>>162015-02-18 19:39
If you add some optimizations on when to quit (e. g. if the number of unmergeable sets at the beginning of your step is already larger than the current leader, drop the branch), the real-life complexity can become quite manageable, especially for smaller values of n.
Name:
Anonymous2015-02-18 20:07
real-life complexity can become quite manageable, especially for smaller values of n.
Any time complexity is manageable for small n.
Name:
Anonymous2015-02-18 20:17
>>16 Actual complexity is n!! 4 * 3 * 2 * 1 is n!, and having each term squared makes things even worse…
The jugger, the jugger jugger man means war The jugger, the jugger jugger man means war The jugger, salute to the jugger means war The jugger, the jugger jugger man means war