mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-13 06:23:00 +08:00
Add knapsack problem.
This commit is contained in:
parent
4474d8909f
commit
80433eb36f
@ -40,6 +40,7 @@
|
|||||||
* [Longest Common Subsequence](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-common-subsequnce) (LCS)
|
* [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)
|
* [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)
|
* [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**
|
* **String**
|
||||||
* [Levenshtein Distance](https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
|
* [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
|
* [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 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)
|
* [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)
|
* [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 subarray
|
||||||
* Maximum sum path
|
* Maximum sum path
|
||||||
* Integer Partition
|
* Integer Partition
|
||||||
|
23
src/algorithms/sets/knapsack-problem/README.md
Normal file
23
src/algorithms/sets/knapsack-problem/README.md
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user