You are on page 1of 1

Three wonderful algorithms 1

Algorithm: Subsets of f1
g
FIRST SUBSET is .
NEXT SUBSET after Y:
Find the last element not in Y (working back from the end).
If there's no such element, then Y was the last subset.

this Remove from Y all elements after , and add to Y. Return
set.
::: n

Algorithm: -subsets of f1
g
FIRST SUBSET is f1
g.
NEXT SUBSET after = f 1
g, where 1
:
 Find the
rst such that + 1 62
 increase by 1, set
= for
, and return the new set
is which case = f ; + 1
g this fails if =
= , in
the last set.
k

::: n

::: k

::: yk

yi

yi

yj

< ::: < yk

j < i

::: n

k yk

Recursive algorithm: Power set of f1


g
If = 0, return fg
Otherwise,
 generate the power set of f1
; 1g
 make a new copy of each subset and adjoin the element to it
 return the set of all sets created.
::: n

::: n

P. J. Cameron, "Combinatorics: Topics, Techniques, Algorithms"

You might also like