Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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. The algorithm for enumerating combinations is discussed in lecture 17 Permutations. Implementation MUST be recursive.

comb.txt contains some skeleton code. Download it and rename it comb.py. A correct implementation of comb:

 python3 comb.py 5 3 

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]
--------BELOW IS THE STARTER CODE GIVEN TO ME----------------------------- import sys def comb(A,n,k,p,lo): """ n>=1, k<=n, p: position to fill, lo: first number to pick print all possible subsets of k out of n """ if __name__ == "__main__": d = len(sys.argv)>3 n = int(sys.argv[1]) k = int(sys.argv[2]) A = [] for i in range(k): A.append(0) if d: print("n:",n,"k:",k) comb(A,n,k,0,0)

I posted this question earlier and the answer I got was mostly right, but not quite. Please help! I cant figure this one out!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

Management style: Fair, consistent? Or plays favorites?

Answered: 1 week ago