Find index of an ordered set of N elements

143 views Asked by At

Problem description: A set of lists of N integers i1,i2,....,iN with 0<= i1<=i2<=i3<=....<=iN <=M, is created by starting with one integer 0<=i1<=M, and repeatedly adding one integer that is greater or equal to the last integer added. When adding the last integer to get the final set of lists, the index runs starting from 0 to BinomialC[M+N,N)]-1.

For example, for M=3, i1=0,1,2,3 

so the lists are

{0},{1},...,{3}. 

Adding another integer i2>=i1 will result in

{0,0},{0,1},{0,2},{0,3},
{1,1},{1,2},{1,3},
{2,2},{2,3}
{3,3}

with indices

0,1,2,3,
4,5,6,
7,8,
9.

This index can be represented in terms of i1,i2,...,iN and M. If the conditions >= were not present, then it would be simply i1*(M+1)^(N-1)+i2*(M+1)^(N-2)+...+iN*(M+1)^(N-N). But, in the case above, there is a negative shift in the index due to the restrictions. For example, N=2 the shift is -i1(i1+1)/2 and index is i = i1*(M+1)^1 + i2*(M+1)^0 -i1(i1+1)/2.

Question: Does anyone especially from mathematics background knows how to write the index for general N element case? or just the final expression? Any help would be appriciated! Thanks!

0

There are 0 answers