Combinatorial numbering rank and unrank

Translate between standard numbering and combinatorial numbering of n choose k.
103 Downloads
Updated 13 Nov 2015

View License

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)

Cite As

Brian Butler (2024). Combinatorial numbering rank and unrank (https://www.mathworks.com/matlabcentral/fileexchange/53976-combinatorial-numbering-rank-and-unrank), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0

* added fig.
* typo
* better fig.

* typo fixed. added 'requirement'