Skip to content

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

Merged
merged 5 commits into from May 26, 2019
Merged

subset_generation #326

merged 5 commits into from May 26, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jul 8, 2018

generate all possible subset of size n of a given array of size r

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 .

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

Copy link
Author

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

@christianbender christianbender left a 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[]

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):

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

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))

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]

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same things as above.

@ghost
Copy link
Author

ghost commented Dec 22, 2018

pls review my changes

@AnupKumarPanwar AnupKumarPanwar merged commit 7f4f565 into TheAlgorithms:master May 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants