[Math Talk #18] Secret of Shuffling - Derangements

2년 전
in math

[1]

0. What is a Derangement?

In mathematics, permutation is an act of arranging all the members of a set into some sequence or order. A permutation which leaves no element fixed is called a derangement . In many cases, we deal with $n$ items (a finite set), each labeled as

$\left\{&space;1,&space;2,&space;...,&space;n&space;\right\}$

So, put another way, a derangement of $n$ objects is a permutation of them without fixed points. The number of derangements of $n$ obejcts is usually written as $D_n$ .

For example, $D_1&space;=&space;0$, since singleton set can not have any derangements. Also $D_2&space;=&space;1$, because only derangement is assigning

$1&space;\mapsto&space;2,\&space;2&space;\mapsto&space;1$

Let's look at one more example $D_3$ . There are total 2 derangements,

Element123
maps to231
maps to312

In general, we need to ask the question:

Of the $n!$ different permutations of $n$ distinct objects, how many leave no object in its original place?

The answer to the question will provide a general formula for $D_n$ as well as

$p_n&space;=&space;\frac{D_n}{n!}$

the probability that a permutation of $n$ objects is a derangement.

1. Old but Gold Recurrence Relation

Viewing $D_1,&space;D_2,D_3,&space;...,&space;D_n,...$ as a sequence $\left\{&space;D_n&space;\right\}$ , let's find a recurrence relation for $D_n$ . Since we already know the value of $D_1$ and $D_2$ , let's focus on the values of $D_n$ for $n&space;\geq&space;3$ .

If a permutation

$\sigma:&space;\left\{&space;1,&space;2,&space;...,&space;n&space;\right\}&space;\rightarrow&space;\left\{&space;1,&space;2,&space;...,&space;n&space;\right\}$

is a derangement, then it must be that $\sigma(1)&space;\neq&space;1$ , which leaves $n-1$ possibilities for it. Among those, choose

$\sigma(1)&space;=&space;k&space;(>&space;1)$

Now there are two possibilities.

1. If $\sigma(k)&space;=&space;1$ , this is nothing but derangement of

$\left\{&space;2,&space;3,&space;...,k-1,&space;k+1,...n&space;\right\}&space;=&space;\left\{&space;1,&space;2,&space;...,&space;n&space;\right\}&space;\setminus&space;\left\{1,k&space;\right\}$

and there are exactly $D_{n-2}$ of these.

2. If $\sigma(k)&space;\neq&space;1$, this is nothing but derangement of

$\left\{&space;2,&space;3,&space;...,&space;n&space;\right\}$

to

$\left\{&space;1,&space;2,&space;...,&space;k-1,&space;k+1,&space;...,&space;n&space;\right\}$

with a restriction $\sigma(k)&space;\neq&space;1$ . The situation is totally equivalent to derangement of

$\left\{&space;2,&space;3,&space;...,&space;n&space;\right\}$

to

$\left\{&space;2,&space;3,&space;...,&space;n&space;\right\}$

if $1$ is viewed as $k$; so there are exactly $D_{n-1}$ of these.

Since our choice of $k$ was arbitrary, summing all those cases gives

$D_n&space;=&space;(n-1)(D_{n-1}&space;+&space;D_{n-2})\&space;(n&space;\geq&space;3)$

How do we solve this?

Clever trick is to divide both sides by $n!$ so that

\begin{align*}&space;\frac{D_n}{n!}&space;&=&space;\frac{(n-1)D_{n-1}}{n!}&space;+&space;\frac{(n-1)D_{n-2}}{n!}&space;\\&space;&=&space;\frac{D_{n-1}}{(n-1)!}&space;\left(1-&space;\frac{1}{n}&space;\right&space;)&space;+&space;\frac{D_{n-2}}{(n-2)!}&space;\cdot&space;\frac{1}{n}\\&space;\iff&space;p_n&space;&=&space;\left(1-&space;\frac{1}{n}&space;\right&space;)&space;p_{n-1}&space;+&space;\frac{1}{n}&space;\cdot&space;p_{n-2}&space;\\&space;\iff&space;(p_n&space;&-&space;p_{n-1})&space;=&space;-\frac{1}{n}&space;(p_{n-1}&space;-&space;p_{n-2})&space;\end{align*}

Defining $q_n&space;=&space;p_n&space;-&space;p_{n-1}$ gives

\begin{align*}&space;q_n&space;&=&space;\left(&space;-\frac{1}{n}&space;\right&space;)&space;\times&space;\left(&space;-\frac{1}{n-1}&space;\right&space;)&space;\times&space;...&space;\times&space;\left(&space;-\frac{1}{1}&space;\right&space;)&space;\\&space;&=&space;(-1)^{n}&space;\frac{1}{n!}&space;\end{align*}

so that

$p_n&space;=&space;q_1&space;+&space;...&space;+&space;q_n&space;=&space;\sum_{i=1}^{n}&space;(-1)^{i}\frac{1}{i!}$

with

$D_n&space;=&space;n!&space;\left(&space;\sum_{i=1}^{n}&space;(-1)^{i}\frac{1}{i!}&space;\right)$

2. The other way around

[2]

We've established the formula for derangement, but there is a more intuitive way of relating the total number of permutations $n!$ with $D_n$ .

We can count the total $n!$ ways by partitioning the ways into $n+1$ disjoint subsets,

$T_0,T_1,T_2,...,T_n$

where $T_r$ is the set of permutations in which there are exactly $n-r$ fixed points. If there are $n-r$ fixed points, we first choose $n-r$ fixed points among $n$ , and arrange leftovers ($r$ elements) to have no fixed points. This gives

$|S_r|&space;=&space;\binom{n}{n-r}D_r&space;=&space;\binom{n}{r}D_r$

so that

$n!&space;=&space;\sum_{r=0}^{n}&space;\binom{n}{r}&space;D_r$

This simple looking relationship is indeed very useful, as we will use in further sections.

3. Expected Number of Fixed points

A rather paradoxical situation arise when we calculate the expeced number of fixed points. Suppose that we perform the experiment of matching the initial arrangement $\left\{&space;1,&space;2,&space;...,&space;n&space;\right\}$ with a random permutation of itself. Define a random variable $X$ as the number of fixed points in single experiment. Then clearly, $X$ can have values

$0,&space;1,&space;2,&space;...,&space;n$

So the expectation is nothing but

$\mathbb{E}[X]&space;=&space;\sum_{r=0}^{n}&space;r\mathbb{P}(X&space;=&space;r)$

In the previous Section, we already obtained the formula for $\mathbb{P}(X&space;=&space;r)$, which is

$\mathbb{P}(X&space;=&space;r)&space;=&space;\frac{|T_{n-r}|}{n!}&space;=&space;\frac{\binom{n}{n-r}&space;D_{n-r}}{n!}$

Now, straightforward calculation gives

\begin{align*}&space;\mathbb{E}[X]&space;&=&space;\sum_{r=0}^{n}&space;r&space;\frac{\binom{n}{n-r}&space;D_{n-r}}{n!}&space;\\&space;&=&space;\sum_{s=0}^{n}&space;(n-s)&space;\frac{\binom{n}{s}D_s}{n!}\&space;(\because&space;s&space;=&space;n-r)&space;\\&space;&=&space;\sum_{s=0}^{n-1}&space;\frac{D_s}{s!(n-s-1)!}\&space;(\because&space;n-n=0)\\&space;&=&space;\frac{1}{(n-1)!}\sum_{s=0}^{n-1}&space;\binom{n-1}{s}D_s&space;\end{align*}

Since

$\sum_{s=0}^{n-1}&space;\binom{n-1}{s}D_s&space;=&space;(n-1)!$

by our previous result in Section 3, we get

$\mathbb{E}[X]&space;=&space;1$

regardless of $n$ .

How should we interpret this weird result? Many of us tend to think the expected number of fixed points will grow as $n$ increases. However, the probability of making an element $i$ as a fixed point is

inversely proportional to $n$

This will help you understand what's going on more clearly. Consider a random variable $X_i$ such that $X_i&space;=&space;1$ if $i$ is a fixed point, and 0 otherwise. Then the expectation of number of fixed points is

$\sum_{i=1}^{n}&space;\mathbb{P}(X_i&space;=&space;1)&space;=&space;\frac{1}{n}&space;\times&space;n&space;=1$

so that $1/n,&space;n$ cancel out making the expectation constant; 1.

4. Asymptotic Property of derangement

[3]

What is the asymptotic behavior of $p_n$ as $n$ gets large?

This is nothing but asking the limit

$p=\lim_{n&space;\rightarrow&space;\infty}&space;p_n&space;=&space;\sum_{i=0}^{\infty}(-1)^i&space;\frac{1}{i!}$

one can easily show that the limit actually exists, and surprisingly, using the well known fact

$e^{x}&space;=&space;\sum_{i=0}^{\infty}&space;\frac{x^i}{i!}\&space;(\text{for&space;all&space;}&space;x&space;\in&space;\mathbb{R})$

gives $p&space;=&space;\frac{1}{e}$ .

What is the asymptotic behavior of $&space; \mathbb{P}(X&space;=&space;r)$ as $n$ gets large?

Recall that we defined random variable $X$ as number of fixed points in single random permutation? Using the definition in Section 2 gives

$\mathbb{P}(X&space;=&space;r)&space;=&space;\frac{\binom{n}{n-r}D_{n-r}}{n!}&space;=&space;\frac{1}{r!}&space;\cdot&space;\frac{D_{n-r}}{(n-r)!}$

We already proved that $\frac{D_{n-r}}{(n-r)!}&space;\rightarrow&space;\frac{1}{e}$, so that

$\mathbb{P}_n(X&space;=&space;r)&space;\rightarrow&space;\frac{e^{-1}}{r!}$

5. Computer Simulation

5-1. Expected number of fixed point revisited

Here is the MATLAB simulation for accumulated expectation of number of fixed points for various $n$ . As the number of simulation grows, you can see the accumulated expectation approaches to unity, regardless of $n$ .

5-2. Asymptotic property of Derangement revisited

Now here is the MATLAB simulation for $p_n$ the probability of having derangement in single permutation.

You can see it clearly converges to $1/e$ , oscillating in small region centered $1/e$ .

6. Conclusion

• Number of derangement of $n$ items is equal to

$n!\sum_{r=0}^{n}&space;\frac{(-1)^r}{r!}$

• The expectated number of fixed points in single random permutation is 1, regardless of $n$ .

• The probability of having derangement converges to $p_n&space;\rightarrow&space;1/e$ .

7. Citations

[1] Image Source Link, By RokerHRO - Own work, CC BY 3.0

[2] Julian Havil, Nonplussed! Mathematical Proof of Implausible Ideas. Chapter 5 page 53

[3] Julian Havil, Nonplussed! Mathematical Proof of Implausible Ideas. Chapter 5 page 56

Sort Order:  trending
·  2년 전

Congratulations @mathsolver! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments

If you no longer want to receive notifications, reply to this comment with the word STOP

You can upvote this notification to help all Steemit users. Learn why here!

·  2년 전

This post has been voted on by the steemstem curation team and voting trail.

There is more to SteemSTEM than just writing posts, check here for some more tips on being a community member. You can also join our discord here to get to know the rest of the community!

·  2년 전

Hi @mathsolver!

Your post was upvoted by utopian.io in cooperation with steemstem - supporting knowledge, innovation and technological advancement on the Steem Blockchain.

Contribute to Open Source with utopian.io

Learn how to contribute on our website and join the new open source economy.

Want to chat? Join the Utopian Community on Discord https://discord.gg/h52nFrV

Yeah!

You just got a 100% upvote from me, courtesy of @justtryme90. I am the All-In-One, Upvoting and Anonymous Flagging BidBot.

Top Profitability

I'm able to calculate and proxy the most profitable bids for the best bidbots out there, so you don't have to! Place your bids via https://bidbot.me.