8000 Fix spelling mistakes · cp-algorithms/cp-algorithms@782f255 · GitHub
[go: up one dir, main page]

Skip to content

Commit 782f255

Browse files
authored
Fix spelling mistakes
1 parent d0f1a33 commit 782f255

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/dynamic_programming/knapsack.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ There are $n$ distinct items and a knapsack of capacity $W$. Each item has 2 att
1414
You have to select a subset of items to put into the knapsack such that the total weight does not exceed the capacity $W$ and the total value is maximized.
1515

1616
In the example above, each object has only two possible states (taken or not taken),
17-
correspoding to binary 0 and 1. Thus, this type of problem is called "0-1 knapsack problem".
17+
corresponding to binary 0 and 1. Thus, this type of problem is called "0-1 knapsack problem".
1818

1919
## 0-1 Knapsack
2020

21-
### Explaination
21+
### Explanation
2222

2323
In the example above, the input to the problem is the following: the weight of $i^{th}$ item $w_{i}$, the value of $i^{th}$ item $v_{i}$, and the total capacity of the knapsack $W$.
2424

@@ -44,7 +44,7 @@ that should be executed in the **decreasing** order of $j$ (so that $f_{j-w_i}$
4444

4545
### Implementation
4646

47-
The alorithm described can be implemented in $O(nW)$ as:
47+
The algorithm described can be implemented in $O(nW)$ as:
4848

4949
```.c++
5050
for (int i = 1; i <= n; i++)
@@ -62,7 +62,7 @@ We can refer to the idea of 0-1 knapsack to define the state: $f_{i, j}$, the ma
6262

6363
It should be noted that although the state definition is similar to that of a 0-1 knapsack, its transition rule is different from that of a 0-1 knapsack.
6464

65-
### Explaination
65+
### Explanation
6666

6767
The trivial approach is, for the first $i$ items, enumerate how many times each item is to be taken. The time complexity of this is $O(n^2W)$.
6868

@@ -82,7 +82,7 @@ $$f_j \gets \max(f_j, f_{j-w_i}+v_i)$$
8282

8383
### Implementation
8484

85-
The alorithm described can be implemented in $O(nW)$ as:
85+
The algorithm described can be implemented in $O(nW)$ as:
8686

8787
```.c++
8888
for (int i = 1; i <= n; i++)
@@ -100,7 +100,7 @@ This is equivalent to being able to put item $i$ into the backpack multiple time
100100

101101
Multiple knapsack is also a variant of 0-1 knapsack. The main difference is that there are $k_i$ of each item instead of just $1$.
102102

103-
### Explaination
103+
### Explanation
104104

105105
A very simple idea is: "choose each item $k_i$ times" is equivalent to "$k_i$ of the same item is selected one by one". Thus converting it to a 0-1 knapsack model, which can be described by the transition function:
106106

@@ -112,9 +112,9 @@ The time complexity of this process is $O(W\sum\limits_{i=1}^{n}k_i)$
112112

113113
We still consider converting the multiple knapsack model into a 0-1 knapsack model for optimization. The time complexity $O(Wn)$ can not be further optimized with the approach above, so we focus on $O(\sum k_i)$ component.
114114

115-
Let $A_{i, j}$ denote the $j^{th}$ item split from the $i^{th}$ item. In the trivial approach discussed above, $A_{i, j}$ represents the same item for all $j \leq k_i$. The main reason for our low efficiency is that we are doing a lot of repetetive work. For example, consider selecting $\{A_{i, 1},A_{i, 2}\}$, and selecting $\{A_{i, 2}, A_{i, 3}\}$. These two situations are completely equivalent. Thus optimizing the spiltting method will greatly reduce the time complexity.
115+
Let $A_{i, j}$ denote the $j^{th}$ item split from the $i^{th}$ item. In the trivial approach discussed above, $A_{i, j}$ represents the same item for all $j \leq k_i$. The main reason for our low efficiency is that we are doing a lot of repetetive work. For example, consider selecting $\{A_{i, 1},A_{i, 2}\}$, and selecting $\{A_{i, 2}, A_{i, 3}\}$. These two situations are completely equivalent. Thus optimizing the splitting method will greatly reduce the time complexity.
116116

117-
The grouping is made more effiecent by using binary grouping.
117+
The grouping is made more efficient by using binary grouping.
118118

119119
Specifically, $A_{i, j}$ holds $2^j$ individual items ($j\in[0,\lfloor \log_2(k_i+1)\rfloor-1]$).If $k_i + 1$ is not an integer power of $2$, another bundle of size $k_i-2^{\lfloor \log_2(k_i+1)\rfloor-1}$ is used to make up for it.
120120

0 commit comments

Comments
 (0)
0