Algorithm to generate permutations
For every number k (0
function permutation(k, s) {
var int factorial:= 1;
for j = 2 to length(s) {
factorial := factorial* (j-1);
swap( s[j - ((k / factorial) mod j)], s[j]);
}
return s;
}
Notation
•k / j denotes integer division of k by j, i.e. the integral quotient without any remainder, and
•k mod j is the remainder following integer division of k by j.
2007-02-19
02:33:11
·
4 answers
·
asked by
arpit k
2
in
Computers & Internet
➔ Programming & Design
s is a set of which i have to generate all possible permutation
2007-02-23
01:19:09 ·
update #1