Subsets Animation
This page illustrates an algorithm for generating all possible subsets of size k taken from the set {1, ..., n}.
Each row is derived from the previous row using the following procedure:
- Find the smallest element j such that j+1 is not in the set. Replace j by j+1. (Shown in blue)
- If there are any elements to the right of j, leave them where they are. (Shown in gray)
- If there are any elements to the left of j, push them as far to the left as possible. (Shown in red)
For more details, see:
- Combinatorics: Topics, Techniques, Algorithms by Peter J. Cameron (1994), Algorithm 3.12.3, page 43
© 2015 Andrew Leverentz