An efficient function for k-th combination with no repetition?
Show older comments
I am looking for a function that accepts a vector V of n elements with no repetition and integers k, i, and returns the i-th combination (in lexicographic order) of k elements of V. It is essential the function do not generate all the combinations and then select the i-th.
Example: V=[1 2 3 4 5], k= 3, i=6. Expected result is: [1 4 5].
Why? Beacuse all combinations of 3 elements of V ordered lexicographically are: 123, 124, 125, 134, 135, 145, 234, 235, 245, 345. And, so the 6-th is 145.
2 Comments
Akira Agata
on 21 Dec 2018
Question for clarification.
Should the order in a vector V be kept in the output?
Because, if not, all combinations of 3 elements will be 123, 124, 125, 132, 134,.... etc.
ZoranSt
on 21 Dec 2018
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!