From 80433eb36fd5450ad12c3a0eff2952b142a699fa Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Fri, 27 Apr 2018 17:31:04 +0300 Subject: [PATCH] Add knapsack problem. --- README.md | 3 ++- .../sets/knapsack-problem/README.md | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/algorithms/sets/knapsack-problem/README.md diff --git a/README.md b/README.md index 73f57b06..ed6c94b2 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ * [Longest Common Subsequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-common-subsequnce) (LCS) * [Longest Increasing subsequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-increasing-subsequence) * [Shortest Common Supersequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/shortest-common-supersequence) (SCS) + * [Knapsack Problem](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/knapsack-problem) * **String** * [Levenshtein Distance](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences * [Hamming Distance](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/hamming-distance) - number of positions at which the symbols are different @@ -94,7 +95,7 @@ * [Longest Common Substring](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/longest-common-substring) * [Longest Increasing subsequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-increasing-subsequence) * [Shortest Common Supersequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/shortest-common-supersequence) - * Knapsack problem + * [Knapsack Problem](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/knapsack-problem) * Maximum subarray * Maximum sum path * Integer Partition diff --git a/src/algorithms/sets/knapsack-problem/README.md b/src/algorithms/sets/knapsack-problem/README.md new file mode 100644 index 00000000..31a82a8b --- /dev/null +++ b/src/algorithms/sets/knapsack-problem/README.md @@ -0,0 +1,23 @@ +# Knapsack Problem + +The knapsack problem or rucksack problem is a problem in +combinatorial optimization: Given a set of items, each with +a weight and a value, determine the number of each item to +include in a collection so that the total weight is less +than or equal to a given limit and the total value is as +large as possible. + +It derives its name from the problem faced by someone who is +constrained by a fixed-size knapsack and must fill it with the +most valuable items. + +Example of a one-dimensional (constraint) knapsack problem: +which boxes should be chosen to maximize the amount of money +while still keeping the overall weight under or equal to 15 kg? + +![knapsack problem](https://upload.wikimedia.org/wikipedia/commons/f/fd/Knapsack.svg) + +## References + +- [Wikipedia](https://en.wikipedia.org/wiki/Knapsack_problem) +- [YouTube](https://www.youtube.com/watch?v=8LusJS5-AGo)