public class PermuteArray
extends java.lang.Object
Constructor and Description |
---|
PermuteArray(int N) |
Modifier and Type | Method and Description |
---|---|
static java.util.List<int[]> |
createList(int N)
Creates a list of all permutations for a set with N elements.
|
static int |
fact(int N)
Computes N factorial
|
int[] |
next()
Creates the next permutation in the sequence.
|
int |
sgn()
Returns signature of the permutation.
|
public int sgn()
Returns signature of the permutation. This is the sgn() operator and returns
-1 or 1 depending on it being odd or even.
sgn(σ) = ( − 1)m
where m is the number of inversions.
NOTE: This implementation is painfully slow O(N!). There is probably another algorithm out there which is much faster.
public static int fact(int N)
public static java.util.List<int[]> createList(int N)
N
- Number of elements in the list being permuted.public int[] next()