Question: in python, write a function comb(A,n,k,p,lo) that prints all k out of n combinations of 0...n-1 in lexicographical order. The parameters p and lo represent
in python, write a function comb(A,n,k,p,lo) that prints all k out of n combinations of 0...n-1 in lexicographical order. The parameters p and lo represent the current location to be filled (p) and the first number to pick in that location (lo). The array A is used to create and store the current combination
description of algorithm:
place digits d from lo to hi in position p
then recursively place digits in position p+1
lo: previously placed digit +1
hi: n-k for pos 0, n-k+1 for pos 1, n-k+p for pos p
comb(A,5,3,0,0) produces
[0, 1, 2] [0, 1, 3] [0, 1, 4] [0, 2, 3] [0, 2, 4] [0, 3, 4] [1, 2, 3] [1, 2, 4] [1, 3, 4] [2, 3, 4]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
