Number of mappings of letters to letters

46 Views Asked by At

Consider $n$ distinct objects. How many 1:1 mappings exist, with the additional restriction that no object is mapped to itself?

Clearly, there are $n!$ mappings without the restriction, so I expect the solution to be of the form $$n!-X$$

where $X$ represents the number of permutations in which at least one object is mapped to itself.

I've made quite a few attempts at calculating $X$, but it always results in recognizing that I am under-counting certain situations.

1

There are 1 best solutions below

0
On

Let's generalize this with a small sets {1,2,3,4,5,6,7} and {1,2,3,4,5,6} but as we figure it out transfer to a larger set. Oh, and let's consider 2 cases.

Case 1: $n$ is odd.

We have $n-1$ chooses we may map $a_1 = 1$ to. Wolog let's say we mapped it to $b_1=2$. Let's choose $a_2$ so that $a_2 \ne b_1$. We have $n-2$ choices of values of $b_2$ for it to be mapped to. Repeat.

So wolog let's assume we have mapped $a_1 = 1 \rightarrow b_1=2; a_2 = 3 \rightarrow b_2 = 4; a_3 = 5 \rightarrow b_3 = 6$.

We have had $6*5*4= (n-1)!/\lfloor n/2 \rfloor!$ ways to choose such mappings.

Now we have three distinct sets $A = \{a_i\}=\{1,3,5\}; B = \{b_i\}=\{2,4,6\}; C = \{c\}=\{7\}$. All $a_i$ have been mapped from, but none have been mapped to. All $b_i$ have been mapped to, but none have been mapped from. $c$ is the single odd element that has neither been mapped to and from. Map $c$ to one of the elements of $A$ (as we can't map it to itself and all the elements of $B$ have all been mapped to). There are $\lfloor n/2 \rfloor$ such elements.

So so far there are $\{(n-1)!/\lfloor n/2 \rfloor!\}*\lfloor n/2 \rfloor$ ways to do this.

Then we can map the members of $B$ to either one of the remaining members of $A$ or to $c$ There are $\lfloor n/2 \rfloor!$ ways to do this.

So there are $\{(n-1)!/\lfloor n/2 \rfloor!\}*\lfloor n/2 \rfloor\lfloor n/2 \rfloor!=(n-1!)\lfloor n/2 \rfloor$.

Case 2: $n$ is even.

This is the same except we don't have the set $C$.

There are $5*4*3 = \frac {(n-1)!}{(n/2 - 1)!}$ ways to map $A$ into $B$.

There are $(n/2)!$ ways to map $B$ to $A$.

For a total of $ \frac {(n-1)!}{(n/2 - 1)!}*(n/2)! = (n-1)!*(n/2)$.

So either way the total number of ways is: $(n-1!)\lfloor n/2 \rfloor$.

====

On first blush, it might seem weird that we are picking our $a_i$ is a specific order ($n$ choices for the first $a_1$, $n-2$ for the second and so one) but when you realize in calculating combinations, the order in which you choice which should be the first and which should be the second don't matter as long as you calculate the options accurately, there is no reason you shouldn't do this.

There is no reason why after calculating we have $n-1$ chooses to map $1$ to that the next element to consider mapping has to be $2$. We can specify "anything but $f(1)$" with no worry of consequence.