Algorithm for finding the cycle-decomposition of a permutation.

combinatoricsfinite-groupspermutation-cyclespermutations

Consider an arbitrary permutation $\sigma\colon I_n\to I_n$, where $I_n \equiv \{1,\dots,n\}$. We know from the cycle-decomposition theorem that the set $I_n$ can be partitioned into various disjoint cycles of $\sigma$.

For example, take $\sigma = (2~5~4~3~1)$ (using one-line notation). It's easy to see that $I_5$ can be partitioned into the two cycles of $\sigma$, which are $\{3,4\}$ and $\{1,2,5\}$.

My two questions are:

  1. Is there a general efficient algorithm for finding the cycle-decomposition of an arbitrary permutation?
  2. Is there a method for computing the total number of cycles in the cycle-decomposition of an arbitrary permutation without having to find the decomposition itself? In the above example, this would be $2$.

Regarding the first question, the only (probably naive) algorithm that comes to my mind is to go trough the elements of $I_n$ one by one and in each iteration, apply the permutation as many times as needed to get back to the initial element, and regard that as a cycle. You can obviously skip the elements in the loop that have already been added to the list of cycles. However, I don't think this is very efficient.

Best Answer

  1. Yes, there is a linear time algorithm. Skipping seen entries ensures each permutation entry is referenced at most $2$ times, so this is linear time.

  2. You cannot determine the number of cycles a permutation has in sublinear time. Indeed, suppose that you have only looked at $n-2$ entries of the permutation. Depending on the permutation for the remaining $2$ unseen items, there will be one of two different possible answers for the question "How many cycles does the permutation have?". The two answers differ by one, since switching two elements either mergers two cycles or breaks one apart. This shows an algorithm cannot always succeed with this work alone. Therefore, at least $n-2$ look-ups are necessary, so any algorithm must be $\Omega(n)$.

Related Question