This is the algorithm (pseudocode) I have right now for finding all subsets for a given set with length k:
void allSubsets(set[]) {
for (i = 0; i<k; i++) {
for (j = i + 1; j<k; j++) {
print(set[i...j]);
}
}
}
But it's run-time is O(n^2). Can anybody improve this?
\binom{n}{k}
subsets of size k. For fixed k, you're looking at O(n^k) being optimal. – Peter Taylor Jun 15 '12 at 9:35