排列公式和组合公式_排列与组合:排列公式与组合公式之间有什么区别?

排列公式和组合公式

Here's the short version.

这是简短的版本。

Let's take ringing bells in a church as an example.

让我们以教堂的钟声为例。

A permutation is an ordering of the bells. You're figuring out the best order to ring them in.

排列是钟声的排序。 您正在寻找最好的顺序来打电话给他们。

A combination is the choice of bells. You're choosing the bells to ring. If you have too many bells, you'd first choose them, and then think about ordering them.

铃声是一种选择。 您正在选择响铃。 如果铃铛太多,则首先选择它们,然后考虑订购它们。

This gives rise to the familiar identity: (n P r) = (n C r) * r!

这引起了熟悉的身份: (n P r) = (n C r) * r!

The way to order r items out of n is to first choose r items out of n, and then order the r items (r! )

顺便顺序r项目出来n是先选择r项目出来的n ,然后责令r项目( r!

And, this means (n P r) = n! / (n-r)! and (n C r) = n! / ( (n-r)! * r! )

并且,这意味着(n P r) = n! / (nr)! (n P r) = n! / (nr)! 并且(n C r) = n! / ( (nr)! * r! ) (n C r) = n! / ( (nr)! * r! )

But do you want to know how to remember this forever?

但是您想知道如何永远记住这一点吗?

I'm a big fan of first principles thinking. To understand a problem, get to the core of it, and reason up from there.

我非常喜欢第一原理的思想 。 要了解问题,请先找到问题的核心,然后从那里进行推理。

Not doing this is usually the source of confusion: if I don't understand how things work, I don't know where to hang the concepts. My mental framework isn't complete, so I decide to just remember it.

不这样做通常是造成混乱的原因:如果我不了解事情的运作方式,那么我就不知道将这些概念挂在哪里。 我的思维框架还不完善,所以我决定只记得它。

As you can imagine, this isn't ideal. So, from time to time, I indulge myself in an exercise of deriving things from the source, and building intuition for how things work.

可以想象,这不是理想的选择。 因此,我会不时地沉迷于从源头衍生事物并树立事物运作方式的直觉的练习。

This time around, we're building intuition for permutations and combinations.

这次,我们正在为排列和组合建立直觉。

For example, do you know why the formula for a combination is (n C r)? Where did this come from? And why are factorials used here?

例如,您知道为什么组合的公式为(n C r)吗? 这个是从哪里来的? 为什么在这里使用阶乘?

Let's begin at the source. Factorials, Permutations, and Combinations were born out of mathematicians playing together, much like how Steve Jobs and Steve Wozniak founded Apple playing together in their garage.

让我们从源头开始。 阶乘,排列和组合是由数学家一起玩而生的,就像史蒂夫·乔布斯和史蒂夫·沃兹尼亚克如何在他们的车库里共同创造苹果一样。

Just like how Apple became a full fledged profitable company, the simple factorial, !, became the atom of an entire field of mathematics: combinatorics.

就像苹果成为成熟的盈利公司一样,简单的阶乘, ! 成为组合数学的整个领域的原子。

Forget everything, let's start thinking from the bottom up.

忘记所有内容,让我们从头开始思考。

The first known interesting use case came from Churches in the 17th century.

第一个已知的有趣用例来自17世纪的教堂。

Have you wondered how the bells are rung in churches? There's a machine that "rings" them in order. We switched to machines because the bells are too big. Also, there are tons of bells.

您是否想知道教堂里的钟声如何? 有一台机器将它们按顺序“响”。 我们因为钟声太大而改用机器。 此外,还有大量的钟声。

How did people figure out the best sequence to ring them in? What if they wanted to switch things up? How could they find the best sound? Each bell tower had up to 16 bells!

人们如何找到最佳的接听顺序? 如果他们想改变事情该怎么办? 他们如何找到最好的声音? 每个钟楼最多可挂16个钟!

You couldn't change how quickly you could ring a bell - the machines only rang one bell every second. The only thing you could do was change the order of the bells. So, this challenge was about figuring out the best order.

您无法更改响铃的速度-机器每秒只响一声。 您唯一可以做的就是更改铃声的顺序。 因此,这一挑战在于寻找最佳订单。

Could we, on the way, also find out all the possible orders? We want to know all possible orders to figure out if it's worth trying them all.

我们能否同时找出所有可能的订单? 我们想知道所有可能的订单,以找出是否值得全部尝试。

A bell ringer, Fabian Stedman took up this challenge.

钟声大发, 法比安·斯特德曼 ( Fabian Stedman)接受了这一挑战。

He started with 2 bells. What are the different orderings he could ring these bells in?[1]

他以2个钟声开始。 他可以按这些铃铛的顺序是什么?[1]

1 and 2. or 2 and 1.

1和2或2和1。

This made sense. There was no other way.

这很有道理。 没有别的办法了。

How about with 3 bells?

三铃怎么样?

1, 2, and 3. 1, 3, and 2.

1、2和3。1、3和2。

Then starting with the second bell,

然后从第二个钟声开始

2, 1, and 3. 2, 3, and 1.

2、1和3。2、3和1。

Then starting with the third bell,

然后从三铃开始

3, 1, and 2. 3, 2, and 1.

3、1和2。3、2和1。

Total, 6.

总计6。

He then realised this was very similar to two bells!

然后他意识到这与两个铃铛非常相似!

If he fixed the first bell, then the number of ways to order the remaining two bells was always two.

如果他固定了第一个铃,那么订购其余两个铃的方式总是两种。

How many ways could he fix the first bell? Any of the 3 bells could be the one!

他可以用几种方法固定钟声? 3个铃铛中的任何一个都可以!

Okay, he went on. He then reached 5 bells.

好吧,他继续。 然后,他达到了五铃。

This is when he realized doing things by hand is unwieldy. You only have so much time in the day, you've got to ring bells, you can't be stuck drawing out all the possible bells. Was there a way to figure this out quickly?

这是当他意识到手工做事很笨拙的时候。 一天中您只有这么多时间,您必须敲响铃铛,您不会被困在所有可能的铃铛上。 有没有办法快速解决这个问题?

He went back to his insight.

他回到了自己的见解。

If he had 5 bells, and he fixed the first bell, all he had to do was figure out how to order 4 bells.

如果他有5个响铃,并且固定了第一个响铃,那么他所要做的就是弄清楚如何订购4个响铃。

For 4 bells? Well, if he had 4 bells, and he fixed the first bell, all he had to do was figure out how to order 3 bells.

4铃? 好吧,如果他有4个铃铛,并且固定了第一个铃铛,那么他要做的就是弄清楚如何订购3个铃铛。

And he knew how to do this!

而且他知道该怎么做!

So, ordering of 5 bells = 5 * ordering of 4 bells.

因此,订购5个铃铛= 5 *订购4个铃铛。

Ordering of 4 bells = 4 * ordering of 3 bells

订购4个铃铛= 4 *订购3个铃铛

Ordering of 3 bells = 3 * ordering of 2 bells.

订购3个铃铛= 3 *订购2个铃铛。

.. You see the pattern, don't you?

..您看到了图案,不是吗?

Fun Fact: This is the key for a programming technique called recursion.

趣闻:这是称为递归的编程技术的关键。

He did too. Although, it took him much longer, since no one near him had already discovered this.[2]

他也是。 虽然,他花了更长的时间,因为附近没有人发现这一点。[2]

Thus, he figured out that the ordering of 5 bells = 5 * 4 * 3 * 2 * 1.

因此,他计算出5个铃铛的顺序为5 * 4 * 3 * 2 * 1

This ordering formula, in 1808, came to be known as the factorial.

这个排序公式在1808年被称为阶乘。

We think of the factorial notation as the base, but the idea existed long before it had a name. It was only when the French mathematician Christian Kramp noticed it being used in a few places that he named it the factorial.

我们认为阶乘表示法是基础,但是这个想法早在它被命名之前就已经存在。 直到法国数学家克里斯蒂安·克兰普(Christian Kramp)注意到它在一些地方使用时,他才将其命名为阶乘。

This ordering of bells is called a permutation.

钟声的这种顺序称为排列。

A Permutation is an ordering of items.

排列是项目的排序。

When learning something, I think it helps to look at things from every different angle, to solidify understanding.

学习某些东西时,我认为从各个不同角度看待事物有助于巩固理解。

What if we tried to derive the formula above directly, without trying to reduce the problem to a smaller number of bells?We have 5 spaces, right?

如果我们尝试直接推导上面的公式而不试图将问题减少到更少的响铃次数该怎么办?我们有5个空格,对吗?

How many ways can we choose the first bell? 5, because that's the number of bells we have.

我们可以选择多少种铃铛? 5 ,因为那是我们的钟声数量。

The second bell? Well, we used up one bell when we placed it in the first position, so we have 4 bells left.

第二钟? 好吧,当我们把它放在第一个位置时,我们用光了一个铃铛,所以还剩下4个铃铛。

The third bell? Well, we've chosen the first two, so there are only 3 bells left to choose from.

第三铃? 好吧,我们选择了前两个,所以只剩下3个铃铛可供选择。

The fourth bell? Only 2 bells left, so 2 options. The fifth bell? Only 1 left, so 1 option.

第四铃? 仅剩2个钟声,因此有2个选择。 第五铃? 仅剩1个,因此有1个选项。

And there we have it, the total number of orderings is 5 * 4 * 3 * 2 * 1

至此,订购总数为5 * 4 * 3 * 2 * 1

Thus, we have our first general formula.

因此,我们有了第一个通用公式。

The number of ways to order N items is N!

订购N件商品的方式为N!

排列 (The Permutation)

Now, we're faced with a different problem. The king ordered new bells to be made for every church. Some are nice, some are okay, some will make you go deaf. But every one is unique. Each makes its own sound. A deafening bell surrounded by nice bells can sound majestic.

现在,我们面临着另一个问题。 国王下令为每座教堂制作新的铃铛。 有些很好,有些还可以,有些会使您充耳不闻。 但是每个人都是独一无二的。 每个人都有自己的声音。 震耳欲聋的铃铛被漂亮的铃铛包围着,听起来威风ma。

But, our bell tower still holds 5 bells, so we need to figure out the best ordering out of 8 bells that the skilled bell makers made.

但是,我们的钟楼仍可容纳5个响铃,因此我们需要从熟练的响铃制造商制作的8个响铃中找出最佳排序。

Using the above logic, we can proceed.

使用以上逻辑,我们可以继续进行。

For the first bell, we can choose any of the 8 bells.

对于第一个铃声,我们可以选择8个铃声中的任何一个。

For the second bell, we can choose any of the remaining 7 bells... and so on.

对于第二个铃声,我们可以选择其余7个铃声中的任何一个...等等。

In the end, we get 8 * 7 * 6 * 5 * 4 possible orderings of 8 bells in 5 spaces.

最后,我们得到5个空间中8个铃铛的8 * 7 * 6 * 5 * 4可能的顺序。

If you're familiar with the formula version of (n P r), which is n! / (n-r)!, don't worry, we'll derive that soon enough, too!

如果您熟悉(n P r)的公式版本,则为n! / (nr)! n! / (nr)! ,请放心,我们也会尽快得出结论!

One bad way to derive it is to multiply both the numerator and denominator by 3! in our example above -

推导它的一种不好的方法是将分子和分母都乘以3! 在上面的示例中-

we get 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 / 3 * 2 * 1 = 8! / 3!.

我们得到8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 / 3 * 2 * 1 = 8! / 3! 8! / 3!

But this doesn't help us understand why this formula works. Before we get there, let's have a look at choosing things, or the Combination.

但这并不能帮助我们理解此公式为何起作用。 在到达那里之前,让我们看一下选择事物或组合。

组合 (The Combination)

Now that we know how to order things, we can figure out how to choose things!

现在我们知道如何订购商品,我们可以找出如何选择商品!

Let's consider the same problem. There's a belltower with 5 bells, and you have 8 bells. However, right now, you don't want to figure out the order of bells (remember that's what a permutation is).

让我们考虑同样的问题。 有一个带有5个铃铛的钟楼,而您有8个铃铛。 但是,现在,您不想弄清楚铃声的顺序(请记住,这是排列的意思)。

Instead, you want to choose the 5 best bells, and let someone else with better taste in music figure out the ordering. In effect, we're breaking the problem down into to parts: First, we figure out which bells to choose. Next, we figure out how to order the chosen bells.

相反,您想选择5个最佳的铃声,然后让音乐口味更好的其他人找出顺序。 实际上,我们将问题分为几部分:首先,我们确定要选择的铃声。 接下来,我们弄清楚如何订购选定的铃铛。

How do you choose the bells? This is the "combination" from permutations and combination.

您如何选择铃声? 这是排列和组合的“组合”。

The combination is a selection. You're being selective. You're choosing 5 bells out of 8 your craftsmen have made.

组合是一个选择。 你是有选择性的。 您从匠人制作的8铃中选择5铃。

Since we know how to order bells, we're going to use this information to figure out how to choose bells. Sounds impossible? Wait till you see the beautiful math involved.

由于我们知道如何订购铃声,因此我们将使用此信息来找出如何选择铃声。 听起来不可能? 等到您看到所涉及的美丽数学。

Let's imagine all the bells are in a line.

让我们想象一下所有的钟声都在一条线上。

Before finding all the ways to choose the bells, let's focus on one way to choose bells.

在找到所有选择铃铛的方法之前,让我们集中讨论一种选择铃铛的方法。

One way is to choose any 5 at random. This doesn't help us solve the problem much, so let's try another way.

一种方法是随机选择任意5个。 这并不能帮助我们解决很多问题,所以让我们尝试另一种方法。

We put the bells in a line, and choose the first 5. This is one way to choose the bells.

我们将铃铛排成一行,然后选择前5个。这是选择铃铛的一种方法。

Notice that, even if we switch positions of the first 5 bells, the choice doesn't change. They're still the same one way to choose 5 unique bells.

请注意,即使我们切换前5个响铃的位置,选择也不会改变。 它们仍然是选择5种独特铃铛的一种方法。

This is true for the last three bells as well.

最后三个钟声也是如此。

Now, the beautiful math trick - for this one way to choose the 5 bells, what are all the ordering of 8 bells where we choose exactly these 5 bells? From the image above, it's all the orderings of the 5 bells (5!) and all the orderings of the remaining three bells (3!).

现在,这是一个美丽的数学技巧-对于这种选择5个响铃的方法,在我们完全选择这5个响铃的情况下,所有8个响铃的顺序是什么? 从上图可以看出,这是5个铃铛( 5! )的所有顺序,其余三个铃铛( 3! )的所有顺序。

Thus, for every single way to choose 5 bells, we have (5! * 3!) orderings of 8 bells.

因此,对于每种选择5个响铃的方式,我们都有( 5! * 3! )个8个响铃的命令。

What are the total possible orderings of 8 bells? 8!.

总共可以订购8个铃铛? 8!

Remember, for each choice of first 5 bells, we have (5! * 3!) orderings of 8 bells which give the same choice.

请记住,对于前5个响铃的每个选择,我们都有( 5! * 3! )8个响铃的顺序,它们给出相同的选择。

Then, if we multiply the number of ways to choose the first 5 bells with all the possible orderings of one choice, we should get the total number of orderings.

然后,如果将选择前5个响铃的方式的数量乘以一个选项的所有可能排序,则应该得到排序的总数。

Ways to choose 5 bells * orderings of one choice = Total orderings

So,

所以,

Ways to choose 5 bells = the total possible orderings / total orderings of one choice.

In math, that becomes:

在数学上,这变成:

(8 C 5) = 8! / ( 5! * 3!)

Lo and behold, we've found an intuitive explanation for how to choose 5 things out of 8.

瞧,我们找到了一个直观的解释,说明如何从8个中选择5个。

Now, we can generalize this. If we have N things, and we want to choose R of them, it means we draw a line at R.

现在,我们可以对此进行概括。 如果我们有N个事物,并且想要选择R个事物,则意味着我们在R处画一条线。

Which means the remaining items will be N-R. So, for one choice of R items, we have R! * (N-R)! orderings which give the same R items.

这意味着其余项目将为NR 。 因此,对于一种R项目,我们有R! * (NR)! R! * (NR)! 给出相同R项目的订单。

For all ways to choose R items, we have N! / (R! * (N-R)!) possibilities.

对于所有选择R项的方法,我们都有N! / (R! * (NR)!) N! / (R! * (NR)!)

The number of ways to choose r items out of n is (n C r) = n! / (r! * (n-r)!)

n选择r项的方法n(n C r) = n! / (r! * (nr)!) (n C r) = n! / (r! * (nr)!)

In colloquial terms, (n C r) is also pronounced n choose r, which helps solidify the idea that combinations are for choosing items.

用口语来说,(n C r)也发音为n choose r ,这有助于巩固组合是用于选择项目的想法。

重新排列-重新审视 (The Permutation - revisited)

With the combination done and dusted, let's come back to Part 2 of our job. Our dear friend chose the best 5 bells by figuring out all possible combinations of 5 bells.

完成并完成组合后,让我们回到工作的第二部分。 我们亲爱的朋友通过找出5个铃铛的所有可能组合,选择了最好的5个铃铛。

It's our job now to find the perfect melody by figuring out the number of orderings.

现在,通过计算订购数量来找到完美的旋律是我们的工作。

But, this is the easy bit. We already know how to order 5 items. It's 5!, and we're done.

但是,这很容易。 我们已经知道如何订购5件商品。 5! ,我们完成了。

So, to permutate (order) 5 items out of 8, we first choose 5 items, then order the 5 items.

因此,要从8个中置换(排序)5个项目,我们首先选择5个项目,然后对5个项目进行排序。

In other words,

换一种说法,

(8 P 5) = (8 C 5) * 5!

And if we expand the formula, (8 P 5) = (8! / ( 5! * 3!)) * 5!

如果我们展开公式,则(8 P 5) = (8! / ( 5! * 3!)) * 5!

(8 P 5) = 8! / 3!.

(8 P 5) = 8! / 3!

And, we've come full circle to our original formula, derived properly.

而且,我们对原始公式作了全面的介绍,并得出了正确的公式。

The number of ways to order r items out of n is (n P r) = n! / (n-r)!

n订购r项的方式数量为(n P r) = n! / (nr)! (n P r) = n! / (nr)!

排列与组合之间的区别 (Difference between permutation and combination)

I hope this makes the difference between permutations and combinations crystal clear.

我希望这可以使排列和组合之间的区别清晰明了。

Permutations are orderings, while combinations are choices.

排列是顺序,而组合是选择。

To order N elements, we found two intuitive ways to figure out the answer. Both lead to the answer, N!.

为了对N个元素进行排序,我们找到了两种直观的方法来找出答案。 两者都导致答案, N!

In order to permutate 5 out of 8 elements, you first need to choose the 5 elements, then order them. You choose using (8 C 5), then order the 5 using 5!.

为了排列8个元素中的5个,您首先需要选择5个元素,然后对其进行排序。 您选择使用(8 C 5) ,然后使用5!订购5!

And the intuition for choosing R out of N is figuring out all the orderings (N!) and dividing by orderings where the first R and last N-R remain the same (R! and (N-R)!).

N选择R的直觉是找出所有顺序( N! ),然后除以第一个R和最后一个NR保持相同的顺序( R!(NR)! )。

And, that's all there is to permutations and combinations.

而且,这就是排列和组合的全部内容。

Every advanced permutation and combination uses this as a base. Combination with replacement? Same idea. Permutation with identical items? Same idea, only the number of orderings change, since some items are identical.

每个高级排列和组合都以此为基础。 结合更换? 相同的想法。 具有相同项目的排列? 相同的想法,只有订购数量发生变化,因为某些项目是相同的。

If you're interested, we can go into the complex cases in another example. Let me know on Twitter.

如果您有兴趣,我们可以在另一个示例中介绍复杂的案例。 在Twitter上让我知道。

Check out more posts on my blog, and join the weekly mailing list.

我的博客上查看更多帖子,并加入每周邮件列表

尾注 (End notes)

  1. This is how I imagine he figured things out. Don't take it as a lesson in history.

    这就是我想象他想出办法的方式。 不要把它当作历史的教训。
  2. The Indians had, in the 12th century, 400 years before him.

    在十二世纪,印第安人比他早了400年。

翻译自: https://www.freecodecamp.org/news/permutation-vs-combination-what-is-the-difference-between-the-permutation-formula-and-the-combination-formula/

排列公式和组合公式

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值