nextcombi
by Dan Stowell
03 Oct 2008
(Updated 03 Oct 2008)
Given a set of N items, iterate over all the combinations of size R (R<N)
|
Watch this File
|
| File Information |
| Description |
Given a set of N items, we want to do something with all possible subsets of that set which have size K. This method iterates over those subsets in a deterministic fashion. Unlike "nchoosek" (which can return a list of all such combinations) the list of possible combinations is never generated in memory, meaning it should be possible to apply this to quite large K.
Example: to print all combinations of 6C3:
a = 1:3;
while a
disp(a);
a = nextcombi(6, a);
end
The complexity of nextcombi is O(N), so the iteration of all combinations should be O(N * nchoosek(N,K)). |
| MATLAB release |
MATLAB 7.4 (R2007a)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Comments and Ratings (1) |
| 03 Oct 2008 |
John D'Errico
|
|
|
|
Contact us at files@mathworks.com