Skip to content

Create-Add files to greedy_method directory #2082

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 19 commits into from
Jun 9, 2020
Merged

Create-Add files to greedy_method directory #2082

merged 19 commits into from
Jun 9, 2020

Conversation

Apoorve73
Copy link
Contributor

@Apoorve73 Apoorve73 commented Jun 8, 2020

Greedy Method approach is one of the method to solve Optimisation Problems and is widely used.

The file greedy_knapsack.py is an example problem to show the working of greedy approach, along with a test_knapsack file.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@Apoorve73 Apoorve73 changed the title create and add files to greedy_method directory Create-Add files to greedy_method directory Jun 8, 2020
@cclauss
Copy link
Member

cclauss commented Jun 8, 2020

How is this faster or better than https://github.com/TheAlgorithms/Python/search?q=knapsack ?

https://docs.pytest.org/en/latest/goodpractices.html#conventions-for-python-test-discovery
says that pytest will run unit tests in test_*.py or *_test.py files so please modify the test filename.

@cclauss
Copy link
Member

cclauss commented Jun 8, 2020

I am not a fan of creating a new directory here. What do other maintainers think given the other implementations.

@Apoorve73
Copy link
Contributor Author

How is this faster or better than https://github.com/TheAlgorithms/Python/search?q=knapsack ?

https://docs.pytest.org/en/latest/goodpractices.html#conventions-for-python-test-discovery
says that pytest will run unit tests in test_*.py or *_test.py files so please modify the test filename.

Its faster in terms of Time Complexiity. Greedy methods are generally faster. For example, Dijkstra's shortest path algorithm takes O(ELogV + VLogV) time. Dynamic Programming is generally slower. For example, Bellman Ford algorithm takes O(VE) time.

I will change the filename. Thank you @cclauss 👍

@Apoorve73
Copy link
Contributor Author

I am not a fan of creating a new directory here. What do other maintainers think given the other implementations.

Well! Greedy Algo is not the same as Dynamic Programming, so I created a different directory for the same. You may tell me, if these files need to be shifted in an existing directory. 💯

@cclauss
Copy link
Member

cclauss commented Jun 8, 2020

Can we please have a benchmark that proves that this implementation is faster than all other knapsack implementations in this repo.

@Apoorve73
Copy link
Contributor Author

Can we please have a benchmark that proves that this implementation is faster than all other knapsack implementations in this repo.

Yeah sure! Greedy Algorithm is not the best but in some cases, it is! Refer https://www.geeksforgeeks.org/greedy-approach-vs-dynamic-programming/ for a detailed explanation! :)

@TravisBuddy
Copy link

Hey @Apoorve73,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: 40244f00-a984-11ea-9161-4f77e253115e

@TravisBuddy
Copy link

Hey @Apoorve73,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: 0efc7af0-a98a-11ea-9161-4f77e253115e

@Apoorve73
Copy link
Contributor Author

Thank you @cclauss for all the valuable suggestions. I will fix them soon!

@TravisBuddy
Copy link

Hey @Apoorve73,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: aad44860-aa3c-11ea-9064-4d6590cbb359

@Apoorve73 Apoorve73 requested a review from cclauss June 9, 2020 10:38
@TravisBuddy
Copy link

Hey @Apoorve73,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: f62a3670-aa3d-11ea-9064-4d6590cbb359

@Apoorve73
Copy link
Contributor Author

@cclauss kindly review the changes!

@TravisBuddy
Copy link

Hey @Apoorve73,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: 108975c0-aa49-11ea-9064-4d6590cbb359

@TravisBuddy
Copy link

Hey @Apoorve73,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: 6974d6d0-aa4d-11ea-9064-4d6590cbb359

@TravisBuddy
Copy link

Travis tests have failed

Hey @Apoorve73,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 21488530-aa5e-11ea-9064-4d6590cbb359

@TravisBuddy
Copy link

Hey @Apoorve73,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 8a8dad90-aa5e-11ea-9064-4d6590cbb359

@Apoorve73 Apoorve73 requested a review from l3str4nge June 9, 2020 15:20
@Apoorve73
Copy link
Contributor Author

Thank you @cclauss and @mateuszz0000 for assisting me. I have tried my best to fix all the issues and improve code quality. Kindly review it, so as to get my PR merged or to suggest any further changes.

@TravisBuddy
Copy link

Travis tests have failed

Hey @Apoorve73,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: c86ff260-aa65-11ea-9064-4d6590cbb359

@TravisBuddy
Copy link

Travis tests have failed

Hey @Apoorve73,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: d7185170-aa67-11ea-9064-4d6590cbb359

@TravisBuddy
Copy link

Hey @Apoorve73,
Your changes look good to me!

View build log

TravisBuddy Request Identifier: 41b345d0-aa68-11ea-9064-4d6590cbb359

@Apoorve73
Copy link
Contributor Author

Apoorve73 commented Jun 9, 2020

@cclauss , are there any more changes to be performed? :)

@cclauss cclauss merged commit 7be3d0f into TheAlgorithms:master Jun 9, 2020
@Apoorve73
Copy link
Contributor Author

Thanks once again! 👍

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Add Greedy Method Approach

* Update Filename

* Update Variable and Links

* Fixed flake8 bugs

* Update unittest filename

* Update unittest filename

* Final unittest filename update

* Pythonic Code formatting

* flake8 fixes

* lowercase function name

* Add zip function

* Add zip function

* params lowercase

* Travis CI fixes

* Update and rename knapsack_problem.py to knapsack.py

* Update test_knapsack.py

* Fix bugs

* Rename knapsack.py to greedy_knapsack.py

* Update test_knapsack.py

Co-authored-by: Christian Clauss <cclauss@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants