Combinatorial numbering rank and unrank
The sequence of combinations defined by N-choose-k (no ordering, no replacement) form a sequence that can be lengthy. These routines provide a way to translate between this sequence and the standard sequence of whole numbers and to advance within the sequence. I find this quite useful when one desires to break this sequence into equal chunks for parallel processing purposes. These sets are assumed to be sorted into lexicographic (like alphabetic) order.
Short example with n=5, k=3:
set,s rank,r
------ -------
[1 2 3] 0
[1 2 4] 1
[1 2 5] 2
[1 3 4] 3
[1 3 5] 4
[1 4 5] 5
[2 3 4] 6
[2 3 5] 7
[2 4 5] 8
[3 4 5] 9
r = kSubsetLexRank(s,k,n)
s = kSubsetLexUnrank(r,k,n)
s = kSubsetLexSuccessor(curset,k,n)
Citation pour cette source
Brian Butler (2024). Combinatorial numbering rank and unrank (https://www.mathworks.com/matlabcentral/fileexchange/53976-combinatorial-numbering-rank-and-unrank), MATLAB Central File Exchange. Extrait(e) le .
Compatibilité avec les versions de MATLAB
Plateformes compatibles
Windows macOS LinuxCatégories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Découvrir Live Editor
Créez des scripts avec du code, des résultats et du texte formaté dans un même document exécutable.
Version | Publié le | Notes de version | |
---|---|---|---|
1.0.0.0 | * added fig.
* typo fixed. added 'requirement' |