0

I have 100 cards labelled from 1 to 100. I place this in a row with all the cards face down. On the first turn I flip the first card. Now this card has a number $n$ on it. I then put this card face-up in the $n$-th position, and flip the original $n$-th card. I then continue this process until I eventually get back the card labelled 1. I will call this a cycle. Now I repeat this process by flipping the next card (from the start) that is not yet face up and continue this process until all 100 cards are face up.

After this process is completed, what is the average number of cycles that I obtain? (An example of some cycles could include $1\rightarrow41\rightarrow57\rightarrow79\rightarrow1$, $2\rightarrow65\rightarrow35\rightarrow71\rightarrow2$, $3\rightarrow3$, etc.

John Smith
  • 1,281

2 Answers2

2

Instead of considering $100$ cards, we assume there are $n$ cards, where $n \geq 1$. Let $X_n$ denotes the # of cycles given $n$ cards and we are interested in the following identity $\mathbb{E}[X_n]$. We also introduce another random variable, denoted as $L$, which denotes the length of the first cycle, thus $L \in [1, n]$. We use the following fact of conditional expectation: $$ \mathbb{E}[X_n] = \sum_{i=1}^n \mathbb{E}[X_n\mid L = i]\cdot\Pr[L = i] \tag{1} $$


We first show how to compute $\Pr[L = i]$. This is in fact not a difficult task.

  • If $i = 1$, then the first position must be the card with value $1$, the probability is $\frac{1}{n}$.
  • If $i = 2$, the first position is a card whose value is not $1$. This probability is $\frac{n-1}{n}$. And the position specified by the first card should contain the card with value $1$ such that the cycle is of length $2$. This probability is $\frac{1}{n-1}$. So the probability of $L = 2$ is just $\frac{n-1}{n} \cdot \frac{1}{n-1} = \frac{1}{n}$.
  • We can generalize the results above to more general $i$. Specifically, $$ \Pr[L = i] = \frac{n-1}{n} \cdot \frac{n-2}{n-1} \cdot \cdots \frac{1}{n-i+1} = \frac{1}{n} \tag{2} $$

We next show how to compute $\mathbb{E}[X_n \mid L = i]$. If the first cycle is of length $i$, the expectation of $X_n$ is just the expectation of # of cycles in the remaining $n - i$ cards plus $1$, i.e., $$ \mathbb{E}[X_n \mid L = i] = \mathbb{E}[X_{n-i}] + 1 \tag{3} $$


To sum up, we have $$ \mathbb{E}[X_n] = \sum_{i=1}^n (\mathbb{E}[X_{n-i}] + 1)\cdot\frac{1}{n} = 1 + \frac{1}{n}\sum_{i=1}^n\mathbb{E}[X_{n-i}]\tag{4} $$ Specially, we have $$ \mathbb{E}[X_0] = 0 \text{ and } \mathbb{E}[X_1] = 1 $$ From $(4)$, we can obtain $$ n\mathbb{E}[X_n] = n + \sum_{i=1}^n\mathbb{E}[X_{n-i}] \tag{5} $$ and $$ (n-1)\mathbb{E}[X_{n-1}] = n - 1 + \sum_{i=1}^{n-1}\mathbb{E}[X_{n-1-i}] \tag{6} $$ Substracting $(6)$ from $(5)$ results in: $$ n \mathbb{E}[X_n] - (n-1)\mathbb{E}[X_{n-1}] = 1 + \mathbb{E}[X_{n-1}] \Rightarrow \mathbb{E}[X_n] = \mathbb{E}[X_{n-1}] + \frac{1}{n} $$ Consequenlty, we conclude that $$ \mathbb{E}[X_n] = \sum_{i=1}^n \frac{1}{i} = H_n $$

joriki
  • 242,601
PSPACEhard
  • 10,381
0

NP-hard has already shown that the probability for the cycle of a given card to have length $i$ is $\frac1n$. Hence the expected number of cards in cycles of length $i$ is $1$, hence the expected number of cycles of length $i$ is $1/i$, hence the total number of cycles is $\sum_{i=1}^n\frac1i=H_n$.

joriki
  • 242,601