public class MathUtils
extends java.lang.Object
| Constructor and Description |
|---|
MathUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int[][] |
getPermutations(int n)
Implements the
Steinhaus–Johnson–Trotter algorithm.
|
static int[][] |
getPermutations(int n,
int offset)
See
getPermutations(int). |
static int[] |
getRandomPermutation(int n)
Returns a permutation of n elements in random order.
|
static <K,V extends java.lang.Comparable<? super V>> |
sortByValue(java.util.Map<K,V> map)
Returns a map that is sorted in descending order by its values.
|
public static <K,V extends java.lang.Comparable<? super V>> java.util.Map<K,V> sortByValue(java.util.Map<K,V> map)
map - public static int[] getRandomPermutation(int n)
n - number of elementspublic static int[][] getPermutations(int n)
work and
dir arrays are the same size thus minimizing any sanity
checks in the code.
Since the factorial of n yields large numbers even for small values
of n one should make sure not to pass arbitrarily large numbers for n
to this method: at best it simply causes an OutOfMemoryError
or may run for a long time.n - number of elementspublic static int[][] getPermutations(int n,
int offset)
getPermutations(int).n - number of elementsoffset - elements are initialized with this offset