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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!