generating permutations

103 Views Asked by At

I have been using this method of exchanging consecutive indexes to generate permutations, but don't know what this algorithm is called. Tried to google search but couldn't find.

Method-

while(current_perm != start_perm) {
        current_perm = exchange ith place with i+1th ;
        increment i ;
        i = i % length of string ;  
}

e.g. 1 2 3 -> 2 1 3 -> 2 3 1 -> 1 3 2 -> 3 1 2 -> 3 2 1 -> 1 2 3

once we reach the starting permutation 1 2 3 we stop.

1

There are 1 best solutions below

1
On

Doing a Bing search for algorithm for generating permutations I came up with Heap's Algorithm.