2
$\begingroup$

As far as my knowledge, this has something to do with the combinatorial number system and lexicographical order, but I can't tell exactly what it is.

An example: let $x = (x_1,x_2,x_3,x_4,x_5)$, in which $x_1 \in \{1,2,3\}$,$x_2 \in \{1,2,3\}$,$x_3 \in \{1,2,3,4,5\}$,$x_4 \in \{1,2,3,4\}$,$x_5 \in \{1,2,3,4,5,6\}$

The total possible choices is $3\times 3\times 5 \times 4 \times 6$. I want to order them this way (when the last possible choice hits the max, then the one before increases 1 and start counting again):

1,1,1,1,1

1,1,1,1,2

$\cdots$

1,1,1,1,6

1,1,1,2,1

$\cdots$

Say I would like to calculate if I order this way, given a random ordering (1,2,4,3,2), what is the index of this tuple?

An inverse problem is given the index, and a set of numbering: $x_1 \in \{1,2,3\}$,$x_2 \in \{1,2,3\}$,$x_3 \in \{1,2,3,4,5\}$,$x_4 \in \{1,2,3,4\}$,$x_5 \in \{1,2,3,4,5,6\}$, can we reconstruct the tuple?

  • 2
    Hint: each index in your tuple is like a place in a decimal number, except instead of having the fourth place represent multiples of 10 * 10 * 10, it represents multiples of 5 * 4 * 6.2017-02-09

1 Answers 1

1

Suppose there are $n$ positions, with the $i$th having $k_i$ possibilities. Define $c_i$ to be the index of the $i$th element in its set. If each set is ${1\ldots k}$, then $c_i=x_i$.

The number of lexicographically smaller sequences than the current one is then seen to be $$\sum\limits_{i=1}^n (c_i-1) \prod\limits_{j=i+1}^n k_j$$

Essentially, just move from left to right and for each position, count the number of smaller elements and multiply with all the possibilities the elements on the right can take.

The same idea can be used to invert as well. The first element is the smallest possible iff the index of the sequence is $\le \prod\limits_{j=2}^n k_j$. If higher, subtract one from the index, divide by this quantity and take the floor. After the first index is fixed, deal with further positions.