Skip to content

Latest commit

 

History

History
9 lines (7 loc) · 738 Bytes

README.md

File metadata and controls

9 lines (7 loc) · 738 Bytes

greedy-knapsack

A Greedy approach to the Knapsack problem (https://en.wikipedia.org/wiki/Knapsack_problem). For educational purposes only, don't use this if you care about performance.

This repository provides:

  • A method (in ''greedy.py'') that implements a greedy algorithm to solve the 0/1 knapsack problem.
  • A method (in ''bruteforce.py'') that finds the optimal solution to the 0/1 knapsack problem by exhaustive search (so we can compare how good the greedy solution is).
  • Unit tests (in ''tests/'') for the two former methods for different problem instance types.
  • A script (in ''optimality_tests.py'') that checks how close the greedy solution is to the optimum (in terms of how much value we take from the knapsack).