Skip to content

subset_generation - #326

Merged
AnupKumarPanwar merged 5 commits into
masterfrom
unknown repository
May 26, 2019
Merged

AnupKumarPanwar merged 5 commits into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jul 8, 2018

Copy link
Copy Markdown

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
Comment thread dynamic_programming/subset_generation Outdated
@@ -0,0 +1,62 @@
# python program to print all subset combination of n element in given set of r element .

Copy link
Copy Markdown

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

@ghost ghost left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

@christianbender christianbender left a comment

Copy link
Copy Markdown

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

Comment thread dynamic_programming/subset_generation Outdated
return

# When no more elements are there to put in data[]

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Comment thread dynamic_programming/subset_generation Outdated
# Driver function to check for above function
arr = [10,20,30,40,50]

r=3

Copy link
Copy Markdown

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

Comment thread dynamic_programming/subset_generation Outdated

# A temporary array to store all combination
# one by one
data = list(range(r))

Copy link
Copy Markdown

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.

Comment thread dynamic_programming/subset_generation Outdated
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]

Copy link
Copy Markdown

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.

# one by one
data = list(range(r))

data = [0]*r

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same things as above.

Comment thread dynamic_programming/subset_generation.py Outdated
@ghost

ghost commented Dec 22, 2018

Copy link
Copy Markdown
Author

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