Function Repository Resource:

# CycleLengthCounts

Count the number of cycles for all possible cycle lengths in a permutation

Contributed by: Wolfram Staff (original content by Sriram V. Pemmaraju and Steven S. Skiena)
 ResourceFunction["CycleLengthCounts"][p] returns a SparseArray of the number of cycles of each length in the permutation p.

## Details and Options

ResourceFunction["CycleLengthCounts"][p] returns a SparseArray of length n, where n=Length[p].
The list {λ1,λ2,} given by Normal is also known as permutation type.

## Examples

### Basic Examples (2)

Find the number of cycles of each length in a permutation:

 In[1]:=
 Out[1]=

Use Normal to see the values:

 In[2]:=
 Out[2]=

The identity permutation of length n has n trivial cycles, that is, n 1-cycles:

 In[3]:=
 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

Verify by counting cycles:

 In[6]:=
 Out[6]=

### Properties and Relations (3)

A reverse of the even-length identity permutation of length n has 2-cycles:

 In[7]:=
 Out[7]=

The number of cycles in a permutation is the total of the cycle length counts:

 In[8]:=
 Out[8]=
 In[9]:=
 Out[9]=
 In[10]:=
 Out[10]=

The sum is n:

 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=

## Version History

• 1.0.0 – 09 July 2020