Home </br>Permutation Generators </br>Combination Generators </br>Set/Subset Generators </br>Cartesian Product Generators </br>Math Functions </br>Ranking Algorithms </br>Number System Algorithms
JNumberTools provides the following 7 ranking algorithms for permutations and combinations. These APIs calculate the lexicographical rank of a given permutation or combination, supporting BigInteger
for large indices, enabling efficient ranking even in massive combinatorial spaces.
Currently Available Algorithms
Calculates the rank of a unique permutation starting from 0th. For example, there are a total of 4!=24 permutations of [0,1,2,3], where the first permutation [0,1,2,3] has rank 0 and the last permutation [3,2,1,0] has the rank of 23.
BigInteger rank = JNumberTools.rankOf().uniquePermutation(3, 2, 1, 0);
Calculates the rank of a k-permutation. For example, if we select 5 elements out of 8 [0,1,2,3,4,5,6,7], there are a total of 8P5 permutations, out of which the 1000th permutation is [8,4,6,2,0].
// Will return 1000
BigInteger rank = JNumberTools.rankOf().kPermutation(8, 4, 6, 2, 0);
Calculates the rank of a repetitive permutation.
// 1,0,0,1 is the 9th repeated permutation of two digits 0 and 1
int elementCount = 2;
BigInteger result = JNumberTools.rankOf()
.repeatedPermutation(elementCount, new Integer[]{1, 0, 0, 1});
Calculates the rank of a given combination. For example, if we generate combinations of 4 elements out of 8 in lex order, the 35th combination will be [1,2,3,4]. Given the input 8 and [1,2,3,4], the API returns 35, the rank of the combination.
BigInteger rank = JNumberTools.rankOf().uniqueCombination(8, 1, 2, 3, 4);
This feature is currently in development and will be available in a future release.
This feature is currently in development and will be available in a future release.
This feature is currently in development and will be available in a future release.
Home </br>Permutation Generators </br>Combination Generators </br>Set/Subset Generators </br>Cartesian Product Generators </br>Math Functions </br>Ranking Algorithms </br>Number System Algorithms