mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-05 00:23:59 +08:00
Update Permutation and Combination cheatsheets. (#963)
This commit is contained in:
@ -5,14 +5,14 @@ When the order doesn't matter, it is a **Combination**.
|
||||
When the order **does** matter it is a **Permutation**.
|
||||
|
||||
**"My fruit salad is a combination of apples, grapes and bananas"**
|
||||
We don't care what order the fruits are in, they could also be
|
||||
"bananas, grapes and apples" or "grapes, apples and bananas",
|
||||
We don't care what order the fruits are in, they could also be
|
||||
"bananas, grapes and apples" or "grapes, apples and bananas",
|
||||
its the same fruit salad.
|
||||
|
||||
## Combinations without repetitions
|
||||
|
||||
This is how lotteries work. The numbers are drawn one at a
|
||||
time, and if we have the lucky numbers (no matter what order)
|
||||
This is how lotteries work. The numbers are drawn one at a
|
||||
time, and if we have the lucky numbers (no matter what order)
|
||||
we win!
|
||||
|
||||
No Repetition: such as lottery numbers `(2,14,15,27,30,33)`
|
||||
@ -30,12 +30,12 @@ It is often called "n choose r" (such as "16 choose 3"). And is also known as th
|
||||
|
||||
Repetition is Allowed: such as coins in your pocket `(5,5,5,10,10)`
|
||||
|
||||
Or let us say there are five flavours of ice cream:
|
||||
Or let us say there are five flavours of ice cream:
|
||||
`banana`, `chocolate`, `lemon`, `strawberry` and `vanilla`.
|
||||
|
||||
We can have three scoops. How many variations will there be?
|
||||
|
||||
Let's use letters for the flavours: `{b, c, l, s, v}`.
|
||||
Let's use letters for the flavours: `{b, c, l, s, v}`.
|
||||
Example selections include:
|
||||
|
||||
- `{c, c, c}` (3 scoops of chocolate)
|
||||
@ -46,23 +46,21 @@ Example selections include:
|
||||
|
||||

|
||||
|
||||
Where `n` is the number of things to choose from, and we
|
||||
choose `r` of them. Repetition allowed,
|
||||
Where `n` is the number of things to choose from, and we
|
||||
choose `r` of them. Repetition allowed,
|
||||
order doesn't matter.
|
||||
|
||||
## Cheat Sheets
|
||||
## Cheatsheet
|
||||
|
||||
Permutations cheat sheet
|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
Combinations cheat sheet
|
||||
| | |
|
||||
| --- | --- |
|
||||
| |  |
|
||||
|
||||

|
||||
|
||||
Permutations/combinations algorithm ideas.
|
||||
|
||||

|
||||
*Made with [okso.app](https://okso.app)*
|
||||
|
||||
## References
|
||||
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 345 KiB |
Binary file not shown.
After Width: | Height: | Size: 324 KiB |
Binary file not shown.
After Width: | Height: | Size: 302 KiB |
BIN
src/algorithms/sets/combinations/images/overview.png
Normal file
BIN
src/algorithms/sets/combinations/images/overview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 142 KiB |
Reference in New Issue
Block a user