I would like to write a function that generates all binary patterns of length n with k bits set. The patterns could be stored in a 2-D array. It looks like I need recursion to achieve this. Any code or pseudocode would be helpful.
Example: if n=5 and k=3 generate this:
11100
11010
11001
10110
10101
10011
01110
01101
00011
00111
I found similar posts: Generate all binary strings of length n with k bits set, but the proposed solutions compute all 2^k combinations.