1 Star 0 Fork 79

zhizou/javascript-algorithms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Combinations

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", 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) we win!

No Repetition: such as lottery numbers (2,14,15,27,30,33)

Number of combinations

Formula

where n is the number of things to choose from, and we choose r of them, no repetition, order doesn't matter.

It is often called "n choose r" (such as "16 choose 3"). And is also known as the Binomial Coefficient.

Combinations with repetitions

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: 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}. Example selections include:

  • {c, c, c} (3 scoops of chocolate)
  • {b, l, v} (one each of banana, lemon and vanilla)
  • {b, v, v} (one of banana, two of vanilla)

Number of combinations

Formula

Where n is the number of things to choose from, and we choose r of them. Repetition allowed, order doesn't matter.

Cheat Sheets

Permutations cheat sheet

Permutations Cheat Sheet

Combinations cheat sheet

Combinations Cheat Sheet

Permutations/combinations algorithm ideas.

Algorithms Idea

References

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhizous/javascript-algorithms.git
git@gitee.com:zhizous/javascript-algorithms.git
zhizous
javascript-algorithms
javascript-algorithms
master

搜索帮助