Repository navigation
subset_generation - #326
Conversation
generate all possible subset of size n of a given array of size r
| @@ -0,0 +1,62 @@ | |||
| # python program to print all subset combination of n element in given set of r element . | |||
|
|
|||
There was a problem hiding this comment.
Your file must have the extension .py
christianbender
left a comment
There was a problem hiding this comment.
Good Work! I have some suggestions
| return | ||
|
|
||
| # When no more elements are there to put in data[] | ||
|
|
There was a problem hiding this comment.
Remove useless empty lines. You can write this:
# comment
def foo():
pass
# comment
def boo():
passAbove each comment you can write a empty line. For example:
def combinationUtil(arr,n,r,index,data,i):
#Current combination is ready to be printed,
# print it
if(index== r):
for j in range(r):
print(data[j],end=" ")
print(" ")
return
# When no more elements are there to put in data[]
if(i>=n):
return
#current is included, put next at next
# location
data[index]=arr[i]
combinationUtil(arr,n,r,index+1,data,i+1)|
|
||
|
|
||
|
|
||
| def printcombination(arr,n,r): |
There was a problem hiding this comment.
The parameter n is useless because you can use the function len(...) within this function.
| # Driver function to check for above function | ||
| arr = [10,20,30,40,50] | ||
|
|
||
| r=3 |
There was a problem hiding this comment.
This variable r is useless because you can put the 3 right away in the function printcombination
|
|
||
| # A temporary array to store all combination | ||
| # one by one | ||
| data = list(range(r)) |
There was a problem hiding this comment.
Instead of this line write data = [0] * n. Is more common.
I made all changes I could . What I mean is I removed all the empty space ....... There some comment extra if you feel removing those comments please do so yourself pls provide spacing as it should be
| #current is included, put next at next | ||
| # location | ||
|
|
||
| data[index]=arr[i] |
There was a problem hiding this comment.
Please add spaces between all operators.
| # one by one | ||
| data = list(range(r)) | ||
|
|
||
| data = [0]*r |
|
pls review my changes |
generate all possible subset of size n of a given array of size r