-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Added fractional knapsack #729
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
Conversation
Added fractional knapsack under the greedy.
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.
Also add some unit tests
README.md
Outdated
@@ -51,7 +51,8 @@ If you want to uninstall algorithms, it is as simple as: | |||
$ pip3 uninstall -y algorithms | |||
|
|||
## List of Implementations | |||
|
|||
- [Greedy](algorithms/arrays) |
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 elements are listed in alphabetical order. Could you add it below dp?
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.
ok no issues I will do it
|
||
"""Time Complexity O(n log n)""" | ||
@staticmethod | ||
def getMaxValue(wt, val, capacity): |
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.
Use snake case
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.
ok
what do you mean by some unit test cases? |
I have added the greedy below the Dp as you requested.
I have made the necessary changes as requested for the snake case in my code.
To add test cases under the test folder, check this PR as guide |
I am new to open-source I don't know how to proceed with the test folder. |
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.
Also add some unit tests
what do you mean by some unit test cases?
To add test cases under the test folder, check this PR as guide
I am new to open-source I don't know how to proceed with the test folder.
Refer to python unittest, this is to add some test cases for your code/functions.
|
||
"""Time Complexity O(n log n)""" | ||
@staticmethod | ||
def get_Max_Value(wt, val, capacity): |
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.
change to snake case with lower case get_Max_Value
-> get_max_value
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.
ok
As requested I have changed get_Max_Value->get_max_value
I have made all necessary changes as asked by you pls allow me to merge my pull request. |
|
Pls add hacktoberfest label also to this pull request |
pls allow me to merge |
thanks for merging |
I have added fractional knapsack code under greedy. Given the weights and values of n items, we need to put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In Fractional Knapsack, we can break items for maximizing the total value of the knapsack.