This may seem like a commonly asked question (e.g. another post with basically the same title), but I am interested in a method of finding an order of an arbitrary permutation matrix, assuming that sometimes the matrix is so large that it is impractical to inspect the lengths manually.
This will be, for example, useful for writing a computer programming function that takes in any permutation matrix P and spits out the order of P (namely, $\min_n P^n=I$).
One method is a brute-force approach, where we keep increase $n$ until we get $P^n=I$. However, I am wondering if there is a cleverer method.
Here is how you can do it, assume the matrix is $n\times n$.
Obtain the permutation $f:\{1,\dots, n\} \rightarrow \{1,\dots, n\}$ where $f(j)$ is equal to the row $x$ such that $A_{x,j} = 1$.
Decompose permutation $f$ into cycles by doing a search over the digraph with vertices $\{1,\dots,n\}$ and edges $i\rightarrow f(i)$.
The order of the matrix is equal to the $\operatorname{lcm}$ of all the cycle lengths.
Some c++ code: