1

I have a question about counting the number of injective (one-to-one) and surjective (onto) functions from $\{1,2,...,n\}$ to itself that satisfy $|f(i)-i| \leq 1, \forall i\in \{1,2,...,n\}$. I appreciate any help.

Thanks in advance and happy new year to you all

vonbrand
  • 27,812

1 Answers1

6

If $f$ is a function from a finite set to itself and it is surjective, then it is necessarily also injective.

If $f$ is a function from a finite set to itself and it is injective, then it is necessarily also surjective.

See Rigorous proof that surjectivity implies injectivity for finite sets

Both questions are then the same and we are asked to count the number of bijections from $\{1,2,\dots,n\}$ to itself.

Now... note that the only choice for $f(1)$ is $1$ or $2$.

In the case that $f(1)=2$, since $f$ must be a bijection, $f(2)\neq 2$. This leaves $f(2)=1$ or $f(2)=3$. Note, however, that if $f(2)=3$, then $f(n)=1$ for some $n\geq 3$ which is a contradiction since that would imply $|f(n)-n|=|1-n|\geq 2$. Thus, if $f(1)=2$ then $f(2)=1$.

Continue via a recurrence relation using the previous observation.

Letting $a_n=$#of bijective functions from $\{1,2,\dots,n\}$ to itself, from the earlier observation we have the recurrence $a_n=a_{n-1}+a_{n-2}$ with initial conditions $a_1=1$ and $a_2=2$.

You should then recognize this as being the fibonacci sequence and can find the closed form using traditional methods if you so choose.

JMoravitz
  • 79,518
  • 1
    Thank you very much. I really appreciate your help. – Shahram Khazaie Jan 01 '16 at 00:02
  • @JMoravitz I am having trouble extrapolating the recurrence relation. Can you elaborate? – Jai T Mar 22 '17 at 14:28
  • Made some progress : f(n) has two possibilities n or n-1. When f(n) = n then f maps {1,....,n-1} to {1,....,n-1}, which gives me $a_{n-1}$ part of the recurrence relation. However i m having trouble when f(n) equals n-1. – Jai T Mar 22 '17 at 14:48
  • @JaiT if f maps n to n-1, what options are available for n-1 to map to? Remember that the function must be bijective. – JMoravitz Mar 22 '17 at 17:26
  • if f = n-1 then maps {1,...,n-1} to {1,...,n-2,n} ? – Jai T Mar 23 '17 at 03:23
  • Incorrect, try again. What is the preimage of $n$? – JMoravitz Mar 23 '17 at 03:25
  • @JaiT I will point out that this entire argument was already explained in my post in the only paragraph that was 3 lines long, except i described it using the first two instead of the last two terms. If $f(n)=n$ then we use one of our desired bijections with restriction from ${1,2,\dots,n-1}$ to ${1,2,\dots,n-1}$ and this can be done in $a_{n-1}$ ways. If $f(n)=n-1$ then $f(n-1)=n$ because there are no other candidates for a preimage to $n$ and so the remaining ${1,2,\dots,n-2}$ map to ${1,2,\dots,n-2}$, and that can be done in $a_{n-2}$ ways – JMoravitz Mar 23 '17 at 03:43