Skip to content
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

Add subsetsum check #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add subsetsum check #10

wants to merge 1 commit into from

Conversation

eveem
Copy link

@eveem eveem commented Oct 17, 2018

#3

@@ -0,0 +1,20 @@
def isSubsetSum (items, length, summ):
Copy link
Owner

Choose a reason for hiding this comment

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

Please provide the comment stating what does the module/function do. Also, include the doctest in the comments.
Doctest reference - https://docs.python.org/2/library/doctest.html

if (items[length - 1] > summ):
return isSubsetSum(items, length - 1, summ);

return isSubsetSum(items, length - 1, summ) or isSubsetSum(items, length - 1, summ - items[length - 1])
Copy link
Owner

Choose a reason for hiding this comment

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

It looks like the code runs in an exponential time. Please try to optimize using Dynamic programming.


return isSubsetSum(items, length - 1, summ) or isSubsetSum(items, length - 1, summ - items[length - 1])

if __name__ == '__main__':
Copy link
Owner

Choose a reason for hiding this comment

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

Please write the test cases in a separate file under the test directory. Check out other test cases which use the pytest to do the testing.
Pytest documentation - https://docs.pytest.org/en/latest/contents.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants