EPI16_5 Generate All Subsets Of SizeK

#1

why do we need

final int numRemaining = k - partialCombination.size();  

and

i <= n && numRemaining <= n-i+1

I tried code without these and also works fine. I just do not understand

i <= n && numRemaining <= n-i+1
0 Likes

#2

It is used for tuning because if we don’t have enough elements to pick in the remaining subarray, there is no need to continue. You can think this as a performance improvement but not for the correctness.

1 Like

#3

You actually don’t even need the i <= n condition. The second one will take care of that.

0 Likes