Counting the number of rows that has repeated elements in the columns

39 Views Asked by At

Suppose the following list: $$ \begin{matrix} j_1 & j_2 & j_3 & j_4\\ 1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 2 \\ 1 & 1 & 1 & 3 \\ 1 & 1 & 2 & 1 \\ 1 & 1 & 2 & 2 \\ & \vdots & \\ 3 & 3 & 3 & 2 \\ 3 & 3 & 3 & 3 \end{matrix} $$ In this list, lets group repeated entries in the columns such that: $$ \begin{matrix} j_1 & j_2 & j_3 & j_4\\ \{1 & 1 & 1 & 1 \}\\ \{1 & 1 & 1\} & \{2\} \\ \{1 & 1 & 1\} & \{3\} \\ & \vdots & \\ \{2 & 2 & 2 & 2\} \\ & \vdots & \\ \{3\} & \{1 & 1 & 1\} \\ \{3 & 3\} & \{2 & 2\} \\ & \vdots & \\ \{3 & 3 & 3 & 3\} \end{matrix} $$

Is there a way to calculate how many entries the subgroups are equal to a certain number? Notice that the subgroup $\{ j_1 j_2 j_3 j_4 \}$ counts 3. On the other hand, it is not that obvious to calculate for the other groups.

Is there a generalized way to calculate this if I have $j_1, j_2, \dots, j_n $ ?

1

There are 1 best solutions below

2
On BEST ANSWER

Answering directly for the generalised case:

Let's denote the arrangement as:

$$\_ \ \_ \ \_ \ .....(n \ times)$$

So let's say that each $\_$ is can be filled with $k$ options. ($k=3$ in the example in the question)

Now if we need to calculate for $r$ repetitions of a option from the $k$ options, ($r=2$ in the example in the question)

First choose an option from $k$ : $\binom{k}{1}$ ways

and then choose $r$ places to place this option: $\binom{n}{r}$

Now look at the other $n-r$ places left, where you can place different characters from $k-1$ options : $\binom{k-1}{n-r} (n-r)!$ ways.

So the total ways:

$$\binom{k}{1}\binom{n}{r}\binom{k-1}{n-r}(n-r)!$$

(Place respective bounds on r,k)

So for your example in the question:

$n=3$, we have total of 3 options: 1, 2, 3 ($k=3$)

So for 3 repetitions, ($r=3$)

$$=\binom{3}{1}\binom{3}{3}\binom{2}{0}(0!)=3$$

For 2 repetitions ($r=2$)

$$=\binom{3}{1}\binom{3}{2}\binom{2}{1}(1)!=18$$

Hope that helped...... :-)