Python
Python copied to clipboard
Added branch_and_bound Algorithm
Describe your change:
This pull request adds a Branch and Bound implementation for solving the 0/1 Knapsack problem in Python.
The algorithm uses a best-first search strategy with a priority queue and prunes non-promising branches using an upper bound calculated via a greedy (fractional knapsack) approach. The implementation is deterministic, well-documented, and includes a passing doctest.
- [x] Add an algorithm?
- [ ] Fix a bug or typo in an existing algorithm?
- [ ] Add or change doctests?
- [x] Documentation change?
Checklist:
- [x] I have read https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md.
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file.
- [x] All new Python files are placed inside an existing directory.
- [x] All filenames are in all lowercase characters with no spaces or dashes.
- [x] All functions and variable names follow Python naming conventions.
- [x] All function parameters and return values are annotated with Python type hints.
- [x] All functions have doctests that pass the automated testing.
- [x] All new algorithms include at least one URL that points to Wikipedia or a similar explanation.
- [ ] This pull request resolves one or more open issues.
References
- https://en.wikipedia.org/wiki/Branch_and_bound
- https://en.wikipedia.org/wiki/Knapsack_problem