Contents

Efficient Generation of Subsets with a Given Sum

D. Roelants van Baronaigien1, Frank Ruskey1
1Department of Computer Science University of Victoria Victoria, B.C, V8W 3P6, Canada

Abstract

Let \(C(n, p)\) denote the set of all subsets of \(\{1, 2, \ldots, n\}\) whose sum is \(p\), and let \(C(n, k, p)\) denote the \(k\)-element sets of \(C(n, p)\). We show that the elements of \(C(n, p)\) and \(C(n, k, p)\) can be generated efficiently by simple recursive algorithms. The subsets are represented by characteristic bitstrings and by lists of elements. These representations can be generated in time that is proportional to the number of subsets generated.