-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
subset_generation #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your file must have the extension .py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Work! I have some suggestions
return | ||
|
||
# When no more elements are there to put in data[] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove useless empty lines. You can write this:
# comment
def foo():
pass
# comment
def boo():
pass
Above 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add spaces between all operators.
# A temporary array to store all combination | ||
# one by one | ||
data = list(range(r)) | ||
|
||
data = [0]*r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same things as above.
pls review my changes |
generate all possible subset of size n of a given array of size r