Skip to content

Commit 80433eb

Browse files
committed
Add knapsack problem.
1 parent 4474d89 commit 80433eb

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* [Longest Common Subsequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-common-subsequnce) (LCS)
4141
* [Longest Increasing subsequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-increasing-subsequence)
4242
* [Shortest Common Supersequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/shortest-common-supersequence) (SCS)
43+
* [Knapsack Problem](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/knapsack-problem)
4344
* **String**
4445
* [Levenshtein Distance](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
4546
* [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 @@
9495
* [Longest Common Substring](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/longest-common-substring)
9596
* [Longest Increasing subsequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-increasing-subsequence)
9697
* [Shortest Common Supersequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/shortest-common-supersequence)
97-
* Knapsack problem
98+
* [Knapsack Problem](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/knapsack-problem)
9899
* Maximum subarray
99100
* Maximum sum path
100101
* Integer Partition
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Knapsack Problem
2+
3+
The knapsack problem or rucksack problem is a problem in
4+
combinatorial optimization: Given a set of items, each with
5+
a weight and a value, determine the number of each item to
6+
include in a collection so that the total weight is less
7+
than or equal to a given limit and the total value is as
8+
large as possible.
9+
10+
It derives its name from the problem faced by someone who is
11+
constrained by a fixed-size knapsack and must fill it with the
12+
most valuable items.
13+
14+
Example of a one-dimensional (constraint) knapsack problem:
15+
which boxes should be chosen to maximize the amount of money
16+
while still keeping the overall weight under or equal to 15 kg?
17+
18+
![knapsack problem](https://upload.wikimedia.org/wikipedia/commons/f/fd/Knapsack.svg)
19+
20+
## References
21+
22+
- [Wikipedia](https://en.wikipedia.org/wiki/Knapsack_problem)
23+
- [YouTube](https://www.youtube.com/watch?v=8LusJS5-AGo)

0 commit comments

Comments
 (0)