Most natural datastructure to store a permutation of distinct elements?

193 Views Asked by At

One easy way to store a permutation of a sequence of distinct elements is as a string (or list) like, "acb" which is clearly a permutation of "abc". However, if I use a string to represent my permutation, I will end up with the possibility of strings like "abb" which do not correspond to any permutation. As a result, the representation of permutations in strings is not dense, so to speak. Lists of indices like [2,3,1] have the same problem.

Alternatively, I could recognize that over N elements there are N! permutations, which can be enumerated in some way. Then, I could store the permutation as an integer. However this is not ideal because the integer would be opaque to interpretation (nobody would know what "permutation number 43" meant), and also because the group structure of the integers over addition is nothing like the group structure of permutations.

Is there a way to represent permutations in a computer that does not have the drawbacks of the methods that I have suggested?

0

There are 0 best solutions below