More notes on combinations/binomial coefficients.

c-declarations
Joshua Potter 2024-02-19 16:16:53 -07:00
parent 4fe3a60534
commit 27adc88529
12 changed files with 306 additions and 8 deletions

View File

@ -75,7 +75,11 @@
"Added Media": [ "Added Media": [
"insertion-sort.gif", "insertion-sort.gif",
"selection-sort.gif", "selection-sort.gif",
"bubble-sort.gif" "bubble-sort.gif",
"lattice-path-chessboard.png",
"lattice-path-chessboard-colored.png",
"lattice-path-before-recurrence.png",
"lattice-path-after-recurrence.png"
], ],
"File Hashes": { "File Hashes": {
"algorithms/index.md": "a5ff7313f71777f1f3536e27dd9894fa", "algorithms/index.md": "a5ff7313f71777f1f3536e27dd9894fa",
@ -149,7 +153,7 @@
"_journal/2024-02/2024-02-11.md": "afee9f502b61e17de231cf2f824fbb32", "_journal/2024-02/2024-02-11.md": "afee9f502b61e17de231cf2f824fbb32",
"encoding/ascii.md": "c01e50f96d0493d94dc4d520c0b6bb71", "encoding/ascii.md": "c01e50f96d0493d94dc4d520c0b6bb71",
"encoding/index.md": "071cfa6a5152efeda127b684f420d438", "encoding/index.md": "071cfa6a5152efeda127b684f420d438",
"c/strings.md": "2c3b6ecf6cf1815598a7be623983856c", "c/strings.md": "813aa7b27c4d9e75b9076681726e11ee",
"logic/truth-tables.md": "7892ceaa416c9a65acc79ca1e6ff778f", "logic/truth-tables.md": "7892ceaa416c9a65acc79ca1e6ff778f",
"logic/short-circuit.md": "26d300f407f14883022d0ef8dc4f7300", "logic/short-circuit.md": "26d300f407f14883022d0ef8dc4f7300",
"logic/boolean-algebra.md": "f9101b2dfdedb73dc13c34c1a70a0010", "logic/boolean-algebra.md": "f9101b2dfdedb73dc13c34c1a70a0010",
@ -173,10 +177,10 @@
"_journal/2024-02/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048", "_journal/2024-02/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
"combinatorics/multiplicative-principle.md": "3e4f600f5300d3d4d64099b8f2bd1458", "combinatorics/multiplicative-principle.md": "3e4f600f5300d3d4d64099b8f2bd1458",
"combinatorics/additive-principle.md": "84dcd0243263b3c53456086ae43fa00f", "combinatorics/additive-principle.md": "84dcd0243263b3c53456086ae43fa00f",
"_journal/2024-02-19.md": "87d762a68e9b8e3c7de0f02d651b1101", "_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629", "_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
"combinatorics/permutations.md": "3c76f548e22f7271280b9ed82ae584ec", "combinatorics/permutations.md": "3c76f548e22f7271280b9ed82ae584ec",
"combinatorics/combinations.md": "0fb5351d4b0ab6c7c8cd17d9423d3dfa" "combinatorics/combinations.md": "8957575cef86f05918a47fcb5bc5f8c1"
}, },
"fields_dict": { "fields_dict": {
"Basic": [ "Basic": [

View File

@ -11,3 +11,4 @@ title: "2024-02-19"
- [ ] Log Work Hours (Max 3 hours) - [ ] Log Work Hours (Max 3 hours)
* Start encoding notes on permutations and combinations, as well as their relationship to one another. * Start encoding notes on permutations and combinations, as well as their relationship to one another.
* Continuing on `printf` fields. Added flashcards for `width` and `precision`.

View File

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

@ -46,6 +46,21 @@ END%%
The syntax for the format placeholder is `%[flags][width][.precision][length]specifier`. The syntax for the format placeholder is `%[flags][width][.precision][length]specifier`.
%%ANKI
Basic
Which header file contains `printf` functionality?
Back: `stdio.h`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441467-->
END%%
%%ANKI
Cloze
{1:`width`} field specifies a {2:minimum} number of characters while {2:`precision`} specifies a {1:maximum}.
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441472-->
END%%
Flag | Description Flag | Description
--------- | ----------- --------- | -----------
`-` | Left-aligns the output `-` | Left-aligns the output
@ -60,6 +75,86 @@ Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia
<!--ID: 1707918756812--> <!--ID: 1707918756812-->
END%% END%%
%%ANKI
Basic
What is the output of `printf("%-2d abc", 100)`?
Back: `100 abc`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441477-->
END%%
%%ANKI
Basic
What is the output of `printf("%-4d abc", 100)`?
Back: `100 abc`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441481-->
END%%
%%ANKI
Basic
What is the output of `printf("%.4d abc", 100)`?
Back: `0100 abc`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441486-->
END%%
%%ANKI
Basic
What is the output of `printf("%04d abc", 100)`?
Back: `0100 abc`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441491-->
END%%
%%ANKI
Basic
What is the output of `printf("%.4s abc", "efg")`?
Back: `efg abc`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441495-->
END%%
%%ANKI
Basic
What is the output of `printf("%.2s abc", "efg")`?
Back: `ef abc`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441499-->
END%%
%%ANKI
Basic
What is the output of `printf("%.2f abc", 0.01234)`?
Back: `0.01 abc`
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441503-->
END%%
%%ANKI
Basic
How does the precision field affect `"%s"` parameters?
Back: Strings are truncated if longer than the specified precision.
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441507-->
END%%
%%ANKI
Basic
How does the precision field affect `"%f"` parameters?
Back: Decimal values are truncated if longer than the specified precision.
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441511-->
END%%
%%ANKI
Basic
What does a negative width field value indicate?
Back: This is actually a positive width with a `-` (left-align) flag.
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
<!--ID: 1708384441515-->
END%%
%%ANKI %%ANKI
Basic Basic
The `-` flag overrides what default behavior? The `-` flag overrides what default behavior?
@ -168,7 +263,7 @@ END%%
%%ANKI %%ANKI
Cloze Cloze
The {`d` and `i`} format specifers output a {decimal `signed int`}. The {`d` and `i`} format specifers work on a {decimal `signed int`}.
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
Tags: printf Tags: printf
<!--ID: 1707852083040--> <!--ID: 1707852083040-->

View File

@ -160,6 +160,180 @@ Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n
<!--ID: 1708368078746--> <!--ID: 1708368078746-->
END%% END%%
## Pascal's Triangle
A visual representation of the binomial coefficient's is in the form of Pascal's Triangle:
```
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
...
```
Terms are generated by adding the two terms above it, formalized via recurrence $$\binom{n}{k} = \binom{n - 1}{k} + \binom{n - 1}{k - 1}$$
%%ANKI
Basic
What recurrence relation does $\binom{n}{k}$ satisfy?
Back: $$\binom{n}{k} = \binom{n - 1}{k - 1} + \binom{n - 1}{k}$$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441360-->
END%%
%%ANKI
Basic
What name is given to the following structure?
```
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
```
Back: Pascal's Triangle.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441393-->
END%%
%%ANKI
Basic
What recurrence relation is Pascal's Triangle based on?
Back: $$\binom{n}{k} = \binom{n - 1}{k - 1} + \binom{n - 1}{k}$$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441399-->
END%%
%%ANKI
Basic
What binomial coefficient is at the peak of Pascal's Triangle?
Back: $\binom{0}{0}$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441405-->
END%%
%%ANKI
Basic
What is the value of $\sum_{k=0}^n \binom{n}{k}$?
Back: $2^n$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441412-->
END%%
%%ANKI
Basic
What is the sum of Pascal's Triangle's $n$th row?
Back: $2^n$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441417-->
END%%
%%ANKI
Basic
Why does $\sum_{k=0}^n \binom{n}{k} = 2^n$?
Back: The summands count the number of subsets of a set of cardinality $n$.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441423-->
END%%
## Lattice Paths
A **lattice path** is one of the shorted possible paths connecting two points on a lattice, moving only horizontally and vertically. By representing each horizontal move by "1" and each vertical move by "0", we see every lattice path has a corresponding bit string.
![[lattice-path-example.png]]
In this example, the total number of lattice paths from point $(0, 0)$ to $(3, 2)$ is therefore $\binom{5}{2} = \binom{5}{3}$.
%%ANKI
Basic
What is the integer lattice?
Back: $\{(x, y) : x \in \omega \land y \in \omega\}$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441429-->
END%%
%%ANKI
Basic
What is a lattice path?
Back: A possible shortest path between two points on an integer lattice.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441434-->
END%%
%%ANKI
Basic
How many lattice paths exist from one corner of a chess board to the opposite corner?
Back: $\binom{16}{8}$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441440-->
END%%
%%ANKI
Basic
How many horizontal moves must a lattice path make between $(0, 0)$ and $(3, 2)$?
Back: $3$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384507600-->
END%%
%%ANKI
Basic
How many vertical moves must a lattice path make between $(0, 0)$ and $(3, 2)$?
Back: $2$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384507605-->
END%%
%%ANKI
Basic
How many moves (horizontal or vertical) must a lattice path make between $(0, 0)$ and $(3, 2)$?
Back: $5$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384507608-->
END%%
%%ANKI
Basic
How do lattice paths relate to bit strings?
Back: Denoting horizontal and vertical moves by $H$ and $V$ makes the relationship clear.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384507611-->
END%%
%%ANKI
Basic
How many lattice paths exist between $(0, 0)$ and $(3, 2)$?
Back: $\binom{5}{2} = \binom{5}{3}$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384507615-->
END%%
%%ANKI
Basic
How is the number of lattice paths in the following shown to mirror the binomial recurrence?
![[lattice-path-before-recurrence.png]]
Back:
It equals the number of lattice paths to $A$ plus the number of lattice paths to $B$.
![[lattice-path-after-recurrence.png]]
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384507618-->
END%%
%%ANKI
Basic
The number of lattice paths to the marked square can be derived by adding the values of which two squares?
![[lattice-path-chessboard.png]]
Back:
![[lattice-path-chessboard-colored.png]]
<!--ID: 1708384441446-->
END%%
## Binomials
A **binomial** is a polynomial containing two terms. Consider $(x + y)^n$.
%%ANKI %%ANKI
Basic Basic
What term describes e.g. $\binom{n}{1}$, $\binom{n}{2}$, etc.? What term describes e.g. $\binom{n}{1}$, $\binom{n}{2}$, etc.?
@ -178,12 +352,36 @@ END%%
%%ANKI %%ANKI
Basic Basic
What are binomial coefficients? Why are binomial coefficients named the way they are?
The coefficients of terms in the expansion of a binomial, e.g. $(x + y)^n$. Back: They are the coefficients of terms in the expansion of a binomial, e.g. $(x + y)^n$.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf). Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708368078764--> <!--ID: 1708368078764-->
END%% END%%
%%ANKI
Basic
How does $(x + y)^n$ relate to bit strings?
Back: Each term $x^ky^{n-k}$ corresponds to a bit string with $k$ `1`s and $n - k$ `0`s.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441451-->
END%%
%%ANKI
Basic
What is the coefficient of $x^3y^{12}$ in $(x + y)^{15}$?
Back: $\binom{15}{3} = \binom{15}{12}$.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441456-->
END%%
%%ANKI
Basic
How is $(x + y)^n$ written to mirror the binomial recurrence?
Back: $(x + y)^n = x \cdot (x + y)^{n-1} + y \cdot (x + y)^{n - 1}$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708384441462-->
END%%
## References ## References
* Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf). * Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB