You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/algebra/all-submasks.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ while (s > 0) {
18
18
19
19
or, using a more compact for statement:
20
20
21
-
```cpp
21
+
```cpp
22
22
for (int s=m; s; s=(s-1)&m)
23
23
... you can use s ...
24
24
```
@@ -49,14 +49,14 @@ for (int m=0; m<(1<<n); ++m)
49
49
for (int s=m; s; s=(s-1)&m)
50
50
... s and m ...
51
51
```
52
-
52
+
53
53
Let's prove that the inner loop will execute a total of $O(3^n)$ iterations.
54
54
55
55
**First proof**: Consider the i-th bit. There are exactly three options for it: it is not included in the mask $m$ (and therefore not included in submask $s$); it is included in $m$, but not included in $s$, or it's included in both $m$ and $s$. As there are a total of $n$ bits, there will be $3^n$ different combinations.
56
56
57
-
**Second proof**: Note that if mask $m$ has $k$ enabled bits, then it will have $2^k$ submasks. As we have a total of $C_n^k$ masks with $k$ enabled bits (see "binomial coefficients"), then the total number of combinations for all masks will be:
57
+
**Second proof**: Note that if mask $m$ has $k$ enabled bits, then it will have $2^k$ submasks. As we have a total of $\binom{n}{k}$ masks with $k$ enabled bits (see "binomial coefficients"), then the total number of combinations for all masks will be:
58
58
59
-
$$\sum_{k=0}^n C_n^k 2^k$$
59
+
$$\sum_{k=0}^n \binom{n}{k} \cdot 2^k$$
60
60
61
61
To calculate this number, note that the sum above is equal to the expansion of $(1+2)^n$ using the binomial theorem. Therefore, we have $3^n$ combinations, as we wanted to prove.
Copy file name to clipboardExpand all lines: src/combinatorics/catalan-numbers.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -62,17 +62,17 @@ void init() {
62
62
```
63
63
64
64
###Analytical formula
65
-
$$C_n = \frac{1}{n + 1} C_{2n}^{n}$$
65
+
$$C_n = \frac{1}{n + 1} {\binom{2n}{n}$$
66
66
67
-
(here $C_{n}^{k}$ denotes the usual binomial coefficient, i.e. number of ways to select $k$ objects from set of $n$ objects).
67
+
(here $\binom{n}{k}$ denotes the usual binomial coefficient, i.e. number of ways to select $k$ objects from set of $n$ objects).
68
68
69
-
The above formula can be easily concluded from the problem of the monotonic paths in square grid. The total number of monotonic paths in the lattice size of $n \times n$ is given by $C_{2n}^{n}$.
69
+
The above formula can be easily concluded from the problem of the monotonic paths in square grid. The total number of monotonic paths in the lattice size of $n \times n$ is given by $\binom{2n}{n}$.
70
70
71
71
Now we count the number of monotonic paths which cross the main diagonal. Consider such paths crossing the main diagonal and find the first edge in it which is above the diagonal. Reflect the path about the diagonal all the way, going after this edge. The result is always a monotonic path in the grid $(n - 1) \times (n + 1)$. On the other hand, any monotonic path in the lattice $(n - 1) \times (n + 1)$ must intersect the diagonal. Hence, we enumerated all monotonic paths crossing the main diagonal in the lattice $n \times n$.
72
72
73
-
The number of monotonic paths in the lattice $(n - 1) \times (n + 1)$ are $C_{2n}^{n-1}$ . Let us call such paths as "bad" paths. As a result, to obtain the number of monotonic paths which do not cross the main diagonal, we subtract the above "bad" paths, obtaining the formula:
73
+
The number of monotonic paths in the lattice $(n - 1) \times (n + 1)$ are $\binom{2n}{n-1}$ . Let us call such paths as "bad" paths. As a result, to obtain the number of monotonic paths which do not cross the main diagonal, we subtract the above "bad" paths, obtaining the formula:
Copy file name to clipboardExpand all lines: src/combinatorics/inclusion-exclusion.md
+21-21Lines changed: 21 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -57,21 +57,21 @@ We want to prove that any element contained in at least one of the sets $A_i$ wi
57
57
Consider an element $x$ occurring in $k \geq 1$ sets $A_i$. We will show it is counted only once in the formula. Note that:
58
58
59
59
* in terms which $|J| = 1$, the item $x$ will be counted **$+\ k$** times;
60
-
* in terms which $|J| = 2$, the item $x$ will be counted **$-\ C_k^2$** times - because it will be counted in those terms that include two of the $k$ sets containing $x$;
61
-
* in terms which $|J| = 3$, the item $x$ will be counted **$+\ C_k^3$** times;
60
+
* in terms which $|J| = 2$, the item $x$ will be counted **$-\ \binom{k}{2}$** times - because it will be counted in those terms that include two of the $k$ sets containing $x$;
61
+
* in terms which $|J| = 3$, the item $x$ will be counted **$+\ \binom{k}{3}$** times;
62
62
* $\cdots$
63
-
* in terms which $|J| = k$, the item $x$ will be counted **$(-1)^{k-1}\cdot C_k^k$** times;
63
+
* in terms which $|J| = k$, the item $x$ will be counted **$(-1)^{k-1}\cdot \binom{k}{k}$** times;
64
64
* in terms which $|J| \gt k$, the item $x$ will be counted **zero** times;
65
65
66
66
This leads us to the following sum of [binomial coefficients](./combinatorics/binomial-coefficients.html):
When $x = 1$, $(1 - x)^k$ looks a lot like $T$. However, the expression has an additional $C_k^0 = 1$, and it is multiplied by $-1$. That leads us to $(1 - 1)^k = 1 - T$. Therefore $T = 1 - (1 - 1)^k = 1$, what was required to prove. The element is counted only once.
74
+
When $x = 1$, $(1 - x)^k$ looks a lot like $T$. However, the expression has an additional $\binom{k}{0} = 1$, and it is multiplied by $-1$. That leads us to $(1 - 1)^k = 1 - T$. Therefore $T = 1 - (1 - 1)^k = 1$, what was required to prove. The element is counted only once.
75
75
76
76
## Usage when solving problems
77
77
@@ -125,23 +125,23 @@ Task: count the number of solutions to the equation.
125
125
126
126
Forget the restriction on $x_i$ for a moment and just count the number of nonnegative solutions to this equation. This is easily done using [binomial coefficients](./combinatorics/binomial-coefficients.html): we want to break a sequence of $20$ units into $6$ groups, which is the same as distributing $5$ "walls" over $25$ slots:
127
127
128
-
$$N_0 = C_{25}^5$$
128
+
$$N_0 = \binom{25}{5}$$
129
129
130
130
We will now calculate the number of "bad" solutions with the inclusion-exclusion principle. The "bad" solutions will be those in which one or more $x_i$ are greater than $9$.
131
131
132
132
Denote by $A_k (k = 1,2\ldots 6)$ the set of solutions where $x_k \ge 9$, and all other $x_i \ge 0 (i \ne k)$ (they may be $\ge 9$ or not). To calculate the size of $A_k$, note that we have essentially the same combinatorial problem that was solved in the two paragraphs above, but now $9$ of the units are excluded from the slots and definitely belong to the first group. Thus:
133
133
134
-
$$ | A_k | = C_{16}^5$$
134
+
$$ | A_k | = \binom{16}{5}$$
135
135
136
136
Similarly, the size of the intersection between sets $A_k$ and $A_p$ is equal to:
137
137
138
-
$$ \left| A_k \cap A_p \right| = C_7^5 $$
138
+
$$ \left| A_k \cap A_p \right| = \binom{7}{5}$$
139
139
140
140
The size of each intersection of three sets is zero, since $20$ units will not be enough for three or more variables greater than or equal to $9$.
141
141
142
142
Combining all this into the formula of inclusions-exceptions and given that we solved the inverse problem, we finally get the answer:
However, asymptotics of this solution is $O(3^k \cdot k)$. To improve it, notice that different $ans(X)$ computations very often share $Y$ sets.
228
228
229
-
We will reverse the formula of inclusion-exclusion and sum in terms of $Y$ sets. Now it becomes clear that the same set $Y$ would be taken into account in the computation of $ans(X)$ of $C_{|Y|}^k$ sets with the same sign $(-1)^{|Y| - k}$.
229
+
We will reverse the formula of inclusion-exclusion and sum in terms of $Y$ sets. Now it becomes clear that the same set $Y$ would be taken into account in the computation of $ans(X)$ of $\binom{|Y|}{k}$ sets with the same sign $(-1)^{|Y| - k}$.
Now our solution has asymptotics $O(2^k \cdot k)$.
234
234
@@ -237,19 +237,19 @@ We will now solve the second version of the problem: find the number of strings
237
237
Of course, we can just use the solution to the first version of the problem and add the answers for sets with size greater than $k$. However, you may notice that in this problem, a set |Y| is considered in the formula for all sets with size $\ge k$ which are contained in $Y$. That said, we can write the part of the expression that is being multiplied by $f(Y)$ as:
Looking at Graham's (Graham, Knuth, Patashnik. "Concrete mathematics" [1998] ), we see a well-known formula for [binomial coefficients](./combinatorics/binomial-coefficients.html):
### The number of ways of going from a cell to another
255
255
@@ -261,7 +261,7 @@ For now, sort the obstacles by their coordinate $x$, and in case of equality —
261
261
262
262
Also just learn how to solve a problem without obstacles: i.e. learn how to count the number of ways to get from one cell to another. In one axis, we need to go through $x$ cells, and on the other, $y$ cells. From simple combinatorics, we get a formula using [binomial coefficients](./combinatorics/binomial-coefficients.html):
263
263
264
-
$$C_{x+y}^{x}$$
264
+
$$\binom{x+y}{x}$$
265
265
266
266
Now to count the number of ways to get from one cell to another, avoiding all obstacles, you can use inclusion-exclusion to solve the inverse problem: count the number of ways to walk through the board stepping at a subset of obstacles (and subtract it from the total number of ways).
267
267
@@ -365,7 +365,7 @@ The asymptotics of our solution is $O(n \log n)$, as for almost every number up
365
365
366
366
Prove that the number of permutations of length $n$ without fixed points (i.e. no number $i$ is in position $i$ - also called a derangement) is equal to the following number:
because if we know that the number of fixed points is equal $x$, then we know the position of $x$ elements of the permutation, and all other $(n-x)$ elements can be placed anywhere.
388
388
389
-
Substituting this into the formula of inclusion-exclusion, and given that the number of ways to choose a subset of size $x$ from the set of $n$ elements is equal to $C_n^x$, we obtain a formula for the number of permutations with at least one fixed point:
389
+
Substituting this into the formula of inclusion-exclusion, and given that the number of ways to choose a subset of size $x$ from the set of $n$ elements is equal to $\binom{n}{x}$, we obtain a formula for the number of permutations with at least one fixed point:
Copy file name to clipboardExpand all lines: src/contrib.md
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,10 @@ And here is the formula in the separate block:
44
44
45
45
$$E = mc^{2}$$
46
46
47
+
###Some conventions
48
+
49
+
* We have agreed as of issue [#83](https://github.com/e-maxx-eng/e-maxx-eng/issues/83) to express binomial coefficients with `\binom{n}{k}` instead of `C_n^k`. The first one renders as $\binom{n}{k}$ and is a more universal convention. The second would render as $C_n^k$.
50
+
47
51
###Adding images
48
52
49
53
Small images could be pushed along with texts to the [/img](https://github.com/e-maxx-eng/e-maxx-eng/tree/master/img) subfolder. Let them be in `PNG` format and less than `200kb`. Then you can refer to them inside the article with the tag:
0 commit comments