Function Repository Resource:

AlternatingPermutationQ

Source Notebook

Determine whether a permutation is an alternating permutation

Contributed by: Motoharu Ito

ResourceFunction["AlternatingPermutationQ"][perm]

returns True if perm is an alternating permutation, and False otherwise.

Details

A permutation is alternating if it starts with an ascent and then descents and ascents come alternate.

Examples

Basic Examples (1) 

Test whether {4,7,2,3,1,6,5} is alternating:

In[1]:=
ResourceFunction["AlternatingPermutationQ"][{4, 7, 2, 3, 1, 6, 5}]
Out[1]=

Scope (1) 

The complement of a reversed alternating permutation is an alternating permutation:

In[2]:=
ResourceFunction["AlternatingPermutationQ"][
 ResourceFunction["ComplementPermutation"][{4, 1, 6, 2, 5, 3}]]
Out[2]=

Publisher

Motoharu Ito

Version History

  • 1.0.0 – 28 November 2022

Source Metadata

Related Resources

License Information