-1

I try to understand algorithm from this Wikipedia article. Initially it is talking about some function f. I specifically getting problem in that part. Below is the paragraph which is quite mathematical. Can anyone explain me that?

For any function $f$ that maps a finite set $S$ to itself, and any initial value $x_0$ in $S$, the sequence of iterated function values

$x_0, x_1 = f(x_0), x_2 = f(x_1), ..., x_i $

must eventually use the same vale twice: there must be some pair of distinct indices $i$ and $j$ such that $x_i$ = $x_j$. Once this happens, the sequence must continue periodically, by repeating the same sequence of values from $x_i$ to $x_{j−1}$. Cycle detection is the problem of finding $i$ and $j$, given $f$ and $x_0$.

Nathaniel
  • 15,071
  • 2
  • 27
  • 52

1 Answers1

0

Suppose $S$ is a set of size $n$. Then considering the values $x_0$, $x_1$, …, $x_n$, using the pigeonhole principle, there must be $0\leqslant i < j \leqslant n$ such that $x_i = x_j$ (because all values $x_k$ are in the set $S$, which contains $n$ distinct values).

Therefore, $x_{j+1} = f(x_j) = f(x_i) = x_{i+1}$, $x_{j+2} = f(x_{j+1}) = f(x_{i+1}) = x_{i+2}$, and so on.

It means that the values $x_j$, $x_{j+1}$, …, $x_{2j-i-1}$ will be exactly the values $x_i$, $x_{i+1}$, …, $x_{j-1}$. There is indeed a cycle of length $j-i$ starting at index $i$.

Nathaniel
  • 15,071
  • 2
  • 27
  • 52