algorithm - Generating half of all permutations by never generating a permutation and its reverse? -


i looking algorithm computes half of possible permutations. example elements b c have following permutations:

a b c

a c b

b c

b c a

c b

c b a

when permutation opposite (in reverse order) of permutation, considered same. example, (a b c) ~ (c b a). need algorithm compute half permutations. in case, either (a b c) (a c b) (b c) or (c b a) (b c a) (c b). suppose different sets of 3 possible too, depending on algorithm.

i have tried searching algorithm, have found language-specific algorithm using included function permutation indexing. need general pseudo-code. i'm working vb.net

thank !

you way:

  1. use double for-loop fix beginning , end of permutation, index[end] > index[beginning];
  2. generate permutations leftover elements , put them in between.

e.g., 4 elements:

a * * b -> c d b, d c b * * c -> b d c, c d b * * d -> b c d, c b d b * * c -> b d c, b d c b * * d -> b c d, b c d c * * d -> c b d, c b d 

since first , last element never last , first elemnt of permutation when generate permutations way, , producing n! / 2 permutations, guaranteed half of permutations.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -