I need to find a memory addressing method to allocate memory (static-hardware) for values corresponding to 'nCk' combination of values from 0 to n-1.
Assuming 'n' as 6 and 'k' as 4, I need to store values (8 or 16 bit) corresponding to combinations:
(1,2,3,4) (1,2,3,5) (1,2,3,6) (1,2,4,5) (1,2,4,6) (1,2,5,6) (1,3,4,5) (1,3,4,6) (1,3,5,6) (1,4,5,6) (2,3,4,5) (2,3,4,6) (2,3,5,6) (2,4,5,6) (3,4,5,6)
Once I have the 'k' (4 here) digits, I should be able to directly access the element corresponding to the 'k' tuple.
Any lower index of the k tuple will be less than the higher indices and none of the indices are equal.
Is it possible to generate an addressing scheme to store and retrieve such data without searching? This needs to be done with minimum computation while address is generated and minimum amount of memory possible. (I think that some memory will be wasted irrespective of the method.)
I thought of linear hashing with different constants for different indices but that leads to a lot of memory loss or high computation complexity for calculating the constants.
Any suggestion regarding this problem will be of great help.
Example:
(combination -> corresponding value in memory)
([(1,2,3,4)->14], [(1,2,3,5)->3], [(1,2,3,6)->-4], [(1,2,4,5)->7], [(1,2,4,6)->22], [(1,2,5,6)->-11], [(1,3,4,5)->5], [(1,3,4,6)->3], [(1,3,5,6)->-1], [(1,4,5,6)->9], [(2,3,4,5)->35], [(2,3,4,6)->4], [(2,3,5,6)->7], [(2,4,5,6)->-2], [(3,4,5,6)->6])
If my input for the above module is (2,3,5,6) I should be able to directly get the value (7).
Edit: 'n' and 'k' are always even.