Write a recursive function that generates all subsets of a fixed size \( k \) of a given set \( [1,2,3...n] \). \( e.g, \) if \( n=5 \) and \( k=3 \), the output will look like
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
Like Find all subsets of a set [1,2,3...n] you can ignore the order in which the subsets are generated.
To generate all subsets of size \( k \) of \( [1, 2, ..., n] \) , first put \( n \) into the current subset being generated and generate all subsets of size \( k-1 \) of \( [1, 2, ..., n-1] \). Then, skipping over element \( n \), generate all subsets of size \( k \) of \( [1, 2, ..., n-1] \). public static void recursiveGenerateKSubsets(boolean[] subset, int n, int k){ |