Difference between revisions of "TADM2E 2.49"

From Algorithm Wiki
Jump to: navigation, search
(Previous answer)
Line 1: Line 1:
Let's <math>f(n)</math> denotes the number of ways <math>n</math> company can
 
merge. We have (assume that ''merge'' in this problem doesn't mean ''acquire''
 
as the later is not commutative)
 
 
- <math>f(2) = 1</math>.
 
- <math>f(3) = 3</math>. From 3 companies, we can first merge any 2 to reduce the size of set to 2. Then, we can merge the 2 new companies. There're 3 ways to select 2 companies from 3.
 
- <math>f(n) = \binom{n}{n-1}f(n-1)</math>. We can merge <math>n</math> companies by first merge <math>n-1</math> ones of them, and then merge the last 2 remaining companies. There're <math>\binom{n}{n-1} = n</math> ways to select a sub set of <math>n-1</math> items from <math>n</math> items. And we already know that there're <math>f(n-1)</math> ways to merge the subset (with <math>n \ge 3</math>.
 
 
So, our final function is:
 
 
<math>
 
f(n) = n.f(n-1) = n(n-1)(n-2)\ldots 3 = \frac{n!}{2}
 
</math>
 
 
 
'''Note''': my answer is different with the old answer by another wiki editor.
 
I don't know if my understanding about the problems is correct. It's up to the
 
next editor to justify and edit this page again.
 
 
My argument is the old solution has some duplication in the way the companies
 
merge together, while my solution is not. Consider <math>n=4</math>.
 
 
The old solution first select 2 companies to merge, reduce the size of set from
 
4 to 3, and then select 2 companies in new set to merge. So, some thing like
 
the following might happen:
 
 
<pre>
 
{a,b,c,d}
 
-> {ab, c, d}, {a, b, cd}
 
-> {ab, cd} and {ab, cd} // This is a duplication, thus, the result is invalid.
 
</pre>
 
 
Meanwhile, my solution first try to combine <math>n-1</math> companies. And because all subset is different with each other, there's no duplication appear.
 
 
 
 
 
Assuming pairwise merges (no k-way merges) we have <math>n-1</math> merge stages where each set of companies is generated from the previous stage (the merged pair being one company). If we characterize each complete merge as different if two companies merge at different stages then we are looking at combinations. In the first stage we have <math>\binom{n}{2}</math> ways to choose a merge pair and a new set for the next stage. Thus, we have the Cartesian product of each stage set and we can calculate the size as:
 
Assuming pairwise merges (no k-way merges) we have <math>n-1</math> merge stages where each set of companies is generated from the previous stage (the merged pair being one company). If we characterize each complete merge as different if two companies merge at different stages then we are looking at combinations. In the first stage we have <math>\binom{n}{2}</math> ways to choose a merge pair and a new set for the next stage. Thus, we have the Cartesian product of each stage set and we can calculate the size as:
  

Revision as of 18:18, 13 November 2016

Assuming pairwise merges (no k-way merges) we have $ n-1 $ merge stages where each set of companies is generated from the previous stage (the merged pair being one company). If we characterize each complete merge as different if two companies merge at different stages then we are looking at combinations. In the first stage we have $ \binom{n}{2} $ ways to choose a merge pair and a new set for the next stage. Thus, we have the Cartesian product of each stage set and we can calculate the size as:

$ \prod_{i=2}^{n} \frac{i(i-1)}{2} = \frac{n! (n-1)!}{2^{n-1}} $

Proof by induction follows easily as long as we agree with the counting process for first non-trivial basis (i.e. $ n=3 $ where our formula indicates there are three different possible merges):

{a,b,c} -> {ab, c} -> {abc}
        -> {a, bc} -> {abc}
        -> {ac, b} -> {abc}

And, since we have three paths we can say that's three merges -- this counts a merge step as the same if it results in the same set of companies going on to the next stage. But, instead if we count the actual merge operations:

{a, b, c} -> {a+b, c}, {(a+b) + c}, {a, b+c}, {a + (b+c)},
             {a+c, b}, {(a+c) + b}

then we need to change the denominator in our previous formula:

$ 2^{n-1} \rightarrow 2^{n-2} $ to get six steps.