<s>
For	O
example	O
,	O
written	O
as	O
tuples	B-Application
,	O
there	O
are	O
six	O
permutations	O
of	O
the	O
set	O
{	O
1	O
,	O
2	O
,	O
3}	O
,	O
namely	O
(	O
1	O
,	O
2	O
,	O
3	O
)	O
,	O
(	O
1	O
,	O
3	O
,	O
2	O
)	O
,	O
(	O
2	O
,	O
1	O
,	O
3	O
)	O
,	O
(	O
2	O
,	O
3	O
,	O
1	O
)	O
,	O
(	O
3	O
,	O
1	O
,	O
2	O
)	O
,	O
and	O
(	O
3	O
,	O
2	O
,	O
1	O
)	O
.	O
</s>
<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
they	O
are	O
used	O
for	O
analyzing	O
sorting	B-Algorithm
algorithms	I-Algorithm
;	O
in	O
quantum	O
physics	O
,	O
for	O
describing	O
states	O
of	O
particles	O
;	O
and	O
in	O
biology	O
,	O
for	O
describing	O
RNA	O
sequences	O
.	O
</s>
<s>
Technically	O
,	O
a	O
permutation	O
of	O
a	O
set	O
is	O
defined	O
as	O
a	O
bijection	B-Algorithm
from	O
to	O
itself	O
.	O
</s>
<s>
The	O
collection	O
of	O
all	O
permutations	O
of	O
a	O
set	O
form	O
a	O
group	O
called	O
the	O
symmetric	B-Algorithm
group	I-Algorithm
of	O
the	O
set	O
.	O
</s>
<s>
The	O
group	O
operation	O
is	O
the	O
composition	B-Application
(	O
performing	O
two	O
given	O
rearrangements	O
in	O
succession	O
)	O
,	O
which	O
results	O
in	O
another	O
rearrangement	O
.	O
</s>
<s>
In	O
elementary	O
combinatorics	O
,	O
the	O
-permutations	O
,	O
or	O
partial	B-Algorithm
permutations	I-Algorithm
,	O
are	O
the	O
ordered	O
arrangements	O
of	O
distinct	O
elements	O
selected	O
from	O
a	O
set	O
.	O
</s>
<s>
This	O
would	O
have	O
been	O
the	O
first	O
attempt	O
on	O
record	O
to	O
solve	O
a	O
difficult	O
problem	O
in	O
permutations	B-Algorithm
and	I-Algorithm
combinations	I-Algorithm
.	O
</s>
<s>
It	O
contains	O
the	O
first	O
use	O
of	O
permutations	B-Algorithm
and	I-Algorithm
combinations	I-Algorithm
,	O
to	O
list	O
all	O
possible	O
Arabic	O
words	O
with	O
and	O
without	O
vowels	O
.	O
</s>
<s>
In	O
a	O
similar	O
manner	O
,	O
the	O
number	O
of	O
arrangements	O
of	O
k	O
items	O
from	O
n	O
objects	O
is	O
sometimes	O
called	O
a	O
partial	B-Algorithm
permutation	I-Algorithm
or	O
a	O
k-permutation	O
.	O
</s>
<s>
Permutations	O
can	O
be	O
defined	O
as	O
bijections	B-Algorithm
from	O
a	O
set	O
onto	O
itself	O
.	O
</s>
<s>
All	O
permutations	O
of	O
a	O
set	O
with	O
n	O
elements	O
form	O
a	O
symmetric	B-Algorithm
group	I-Algorithm
,	O
denoted	O
,	O
where	O
the	O
group	O
operation	O
is	O
function	B-Application
composition	I-Application
.	O
</s>
<s>
In	O
general	O
,	O
composition	B-Application
of	O
two	O
permutations	O
is	O
not	O
commutative	O
,	O
that	O
is	O
,	O
</s>
<s>
As	O
a	O
bijection	B-Algorithm
from	O
a	O
set	O
to	O
itself	O
,	O
a	O
permutation	O
is	O
a	O
function	O
that	O
performs	O
a	O
rearrangement	O
of	O
a	O
set	O
,	O
and	O
is	O
not	O
an	O
arrangement	O
itself	O
.	O
</s>
<s>
A	O
permutation	O
can	O
be	O
decomposed	O
into	O
one	O
or	O
more	O
disjoint	B-Algorithm
cycles	B-Algorithm
,	O
that	O
is	O
,	O
the	O
orbits	O
,	O
which	O
are	O
found	O
by	O
repeatedly	O
tracing	O
the	O
application	O
of	O
the	O
permutation	O
on	O
some	O
elements	O
.	O
</s>
<s>
2-cycles	O
are	O
called	O
transpositions	B-Algorithm
;	O
such	O
permutations	O
merely	O
exchange	O
two	O
elements	O
,	O
leaving	O
the	O
others	O
fixed	O
.	O
</s>
<s>
Since	O
writing	O
permutations	O
elementwise	O
,	O
that	O
is	O
,	O
as	O
piecewise	B-Algorithm
functions	I-Algorithm
,	O
is	O
cumbersome	O
,	O
several	O
notations	O
have	O
been	O
invented	O
to	O
represent	O
them	O
more	O
compactly	O
.	O
</s>
<s>
Cycle	B-Algorithm
notation	I-Algorithm
is	O
a	O
popular	O
choice	O
for	O
many	O
mathematicians	O
due	O
to	O
its	O
compactness	O
and	O
the	O
fact	O
that	O
it	O
makes	O
a	O
permutation	O
's	O
structure	O
transparent	O
.	O
</s>
<s>
that	O
is	O
,	O
as	O
an	O
ordered	O
arrangement	O
of	O
the	O
elements	O
of	O
S	O
.	O
Care	O
must	O
be	O
taken	O
to	O
distinguish	O
one-line	O
notation	O
from	O
the	O
cycle	B-Algorithm
notation	I-Algorithm
described	O
below	O
.	O
</s>
<s>
In	O
mathematics	O
literature	O
,	O
a	O
common	O
usage	O
is	O
to	O
omit	O
parentheses	O
for	O
one-line	O
notation	O
,	O
while	O
using	O
them	O
for	O
cycle	B-Algorithm
notation	I-Algorithm
.	O
</s>
<s>
This	O
form	O
is	O
more	O
compact	O
,	O
and	O
is	O
common	O
in	O
elementary	O
combinatorics	O
and	O
computer	B-General_Concept
science	I-General_Concept
.	O
</s>
<s>
Cycle	B-Algorithm
notation	I-Algorithm
describes	O
the	O
effect	O
of	O
repeatedly	O
applying	O
the	O
permutation	O
on	O
the	O
elements	O
of	O
the	O
set	O
.	O
</s>
<s>
It	O
expresses	O
the	O
permutation	O
as	O
a	O
product	O
of	O
cycles	B-Algorithm
;	O
since	O
distinct	O
cycles	B-Algorithm
are	O
disjoint	B-Algorithm
,	O
this	O
is	O
referred	O
to	O
as	O
"	O
decomposition	O
into	O
disjoint	B-Algorithm
cycles	B-Algorithm
"	O
.	O
</s>
<s>
To	O
write	O
down	O
the	O
permutation	O
in	O
cycle	B-Algorithm
notation	I-Algorithm
,	O
one	O
proceeds	O
as	O
follows	O
:	O
</s>
<s>
Repeat	O
until	O
all	O
elements	O
of	O
S	O
are	O
written	O
in	O
cycles	B-Algorithm
.	O
</s>
<s>
So	O
the	O
permutation	O
(	O
in	O
one-line	O
notation	O
)	O
could	O
be	O
written	O
as	O
in	O
cycle	B-Algorithm
notation	I-Algorithm
.	O
</s>
<s>
While	O
permutations	O
in	O
general	O
do	O
not	O
commute	O
,	O
disjoint	B-Algorithm
cycles	B-Algorithm
do	O
;	O
for	O
example	O
,	O
</s>
<s>
One	O
may	O
combine	O
these	O
equalities	O
to	O
write	O
the	O
disjoint	B-Algorithm
cycles	B-Algorithm
of	O
a	O
given	O
permutation	O
in	O
many	O
different	O
ways	O
.	O
</s>
<s>
1-cycles	O
are	O
often	O
omitted	O
from	O
the	O
cycle	B-Algorithm
notation	I-Algorithm
,	O
provided	O
that	O
the	O
context	O
is	O
clear	O
;	O
for	O
any	O
element	O
x	O
in	O
S	O
not	O
appearing	O
in	O
any	O
cycle	O
,	O
one	O
implicitly	O
assumes	O
.	O
</s>
<s>
The	O
identity	O
permutation	O
,	O
which	O
consists	O
only	O
of	O
1-cycles	O
,	O
can	O
be	O
denoted	O
by	O
a	O
single	O
1-cycle	O
(	O
x	O
)	O
,	O
by	O
the	O
number	O
1	O
,	O
or	O
by	O
id	O
.	O
</s>
<s>
A	O
convenient	O
feature	O
of	O
cycle	B-Algorithm
notation	I-Algorithm
is	O
that	O
cycle	B-Algorithm
notation	I-Algorithm
of	O
the	O
inverse	O
permutation	O
is	O
given	O
by	O
reversing	O
the	O
order	O
of	O
the	O
elements	O
in	O
the	O
permutation	O
's	O
cycles	B-Algorithm
.	O
</s>
<s>
In	O
some	O
combinatorial	O
contexts	O
it	O
is	O
useful	O
to	O
fix	O
a	O
certain	O
order	O
for	O
the	O
elements	O
in	O
the	O
cycles	B-Algorithm
and	O
of	O
the	O
(	O
disjoint	B-Algorithm
)	O
cycles	B-Algorithm
themselves	O
.	O
</s>
<s>
Miklós	O
Bóna	O
calls	O
the	O
following	O
ordering	O
choices	O
the	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
:	O
</s>
<s>
For	O
example	O
,	O
(	O
312	O
)	O
(	O
54	O
)	O
(	O
8	O
)	O
(	O
976	O
)	O
is	O
a	O
permutation	O
in	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
.	O
</s>
<s>
The	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
does	O
not	O
omit	O
one-cycles	O
.	O
</s>
<s>
Sergey	O
Kitaev	O
also	O
uses	O
the	O
"	O
standard	O
form	O
"	O
terminology	O
,	O
but	O
reverses	O
both	O
choices	O
;	O
that	O
is	O
,	O
each	O
cycle	O
lists	O
its	O
least	O
element	O
first	O
and	O
the	O
cycles	B-Algorithm
are	O
sorted	O
in	O
decreasing	O
order	O
of	O
their	O
least	O
,	O
that	O
is	O
,	O
first	O
elements	O
.	O
</s>
<s>
There	O
are	O
two	O
ways	O
to	O
denote	O
the	O
composition	B-Application
of	O
two	O
permutations	O
.	O
</s>
<s>
Since	O
function	B-Application
composition	I-Application
is	O
associative	O
,	O
so	O
is	O
the	O
composition	B-Application
operation	O
on	O
permutations	O
:	O
.	O
</s>
<s>
Therefore	O
,	O
products	O
of	O
more	O
than	O
two	O
permutations	O
are	O
usually	O
written	O
without	O
adding	O
parentheses	O
to	O
express	O
grouping	O
;	O
they	O
are	O
also	O
usually	O
written	O
without	O
a	O
dot	O
or	O
other	O
sign	O
to	O
indicate	O
composition	B-Application
.	O
</s>
<s>
These	O
objects	O
are	O
also	O
known	O
as	O
partial	B-Algorithm
permutations	I-Algorithm
or	O
as	O
sequences	B-Algorithm
without	I-Algorithm
repetition	I-Algorithm
,	O
terms	O
that	O
avoid	O
confusion	O
with	O
the	O
other	O
,	O
more	O
common	O
,	O
meaning	O
of	O
"	O
permutation	O
"	O
.	O
</s>
<s>
Ordered	O
arrangements	O
of	O
k	O
elements	O
of	O
a	O
set	O
S	O
,	O
where	O
repetition	O
is	O
allowed	O
,	O
are	O
called	O
k-tuples	O
.	O
</s>
<s>
There	O
is	O
no	O
restriction	O
on	O
how	O
often	O
an	O
element	O
can	O
appear	O
in	O
an	O
k-tuple	O
,	O
but	O
if	O
restrictions	O
are	O
placed	O
on	O
how	O
often	O
an	O
element	O
can	O
appear	O
,	O
this	O
formula	O
is	O
no	O
longer	O
valid	O
.	O
</s>
<s>
If	O
M	O
is	O
a	O
finite	O
multiset	B-Language
,	O
then	O
a	O
multiset	B-Language
permutation	O
is	O
an	O
ordered	O
arrangement	O
of	O
elements	O
of	O
M	O
in	O
which	O
each	O
element	O
appears	O
a	O
number	O
of	O
times	O
equal	O
exactly	O
to	O
its	O
multiplicity	O
in	O
M	O
.	O
An	O
anagram	O
of	O
a	O
word	O
having	O
some	O
repeated	O
letters	O
is	O
an	O
example	O
of	O
a	O
multiset	B-Language
permutation	O
.	O
</s>
<s>
If	O
the	O
multiplicities	O
of	O
the	O
elements	O
of	O
M	O
(	O
taken	O
in	O
some	O
order	O
)	O
are	O
,	O
,	O
...	O
,	O
and	O
their	O
sum	O
(	O
that	O
is	O
,	O
the	O
size	O
of	O
M	O
)	O
is	O
n	O
,	O
then	O
the	O
number	O
of	O
multiset	B-Language
permutations	O
of	O
M	O
is	O
given	O
by	O
the	O
multinomial	O
coefficient	O
,	O
</s>
<s>
A	O
k-permutation	O
of	O
a	O
multiset	B-Language
M	O
is	O
a	O
sequence	O
of	O
length	O
k	O
of	O
elements	O
of	O
M	O
in	O
which	O
each	O
element	O
appears	O
a	O
number	O
of	O
times	O
less	O
than	O
or	O
equal	O
to	O
its	O
multiplicity	O
in	O
M	O
(	O
an	O
element	O
's	O
repetition	O
number	O
)	O
.	O
</s>
<s>
The	O
arrangements	O
of	O
objects	O
in	O
a	O
circular	O
manner	O
are	O
called	O
circular	B-Algorithm
permutations	I-Algorithm
.	O
</s>
<s>
Two	O
circular	B-Algorithm
permutations	I-Algorithm
are	O
equivalent	O
if	O
one	O
can	O
be	O
rotated	O
into	O
the	O
other	O
(	O
that	O
is	O
,	O
cycled	O
without	O
changing	O
the	O
relative	O
positions	O
of	O
the	O
elements	O
)	O
.	O
</s>
<s>
The	O
following	O
four	O
circular	B-Algorithm
permutations	I-Algorithm
on	O
four	O
letters	O
are	O
considered	O
to	O
be	O
the	O
same	O
.	O
</s>
<s>
The	O
number	O
of	O
circular	B-Algorithm
permutations	I-Algorithm
of	O
a	O
set	O
S	O
with	O
n	O
elements	O
is	O
(	O
n	O
–	O
1	O
)	O
!	O
.	O
</s>
<s>
The	O
number	O
of	O
-permutations	O
with	O
disjoint	B-Algorithm
cycles	B-Algorithm
is	O
the	O
signless	O
Stirling	O
number	O
of	O
the	O
first	O
kind	O
,	O
denoted	O
by	O
.	O
</s>
<s>
The	O
cycles	B-Algorithm
(	O
including	O
the	O
fixed	O
points	O
)	O
of	O
a	O
permutation	O
of	O
a	O
set	O
with	O
elements	O
partition	O
that	O
set	O
;	O
so	O
the	O
lengths	O
of	O
these	O
cycles	B-Algorithm
form	O
an	O
integer	O
partition	O
of	O
,	O
which	O
is	O
called	O
the	O
cycle	O
type	O
(	O
or	O
sometimes	O
cycle	O
structure	O
or	O
cycle	O
shape	O
)	O
of	O
.	O
</s>
<s>
There	O
is	O
a	O
"	O
1	O
"	O
in	O
the	O
cycle	O
type	O
for	O
every	O
fixed	O
point	O
of	O
,	O
a	O
"	O
2	O
"	O
for	O
every	O
transposition	B-Algorithm
,	O
and	O
so	O
on	O
.	O
</s>
<s>
More	O
precisely	O
,	O
the	O
general	O
form	O
is	O
,	O
where	O
are	O
the	O
numbers	O
of	O
cycles	B-Algorithm
of	O
respective	O
length	O
.	O
</s>
<s>
In	O
general	O
,	O
composing	O
permutations	O
written	O
in	O
cycle	B-Algorithm
notation	I-Algorithm
follows	O
no	O
easily	O
described	O
pattern	O
–	O
the	O
cycles	B-Algorithm
of	O
the	O
composition	B-Application
can	O
be	O
different	O
from	O
those	O
being	O
composed	O
.	O
</s>
<s>
Here	O
,	O
is	O
the	O
conjugate	O
of	O
by	O
and	O
its	O
cycle	B-Algorithm
notation	I-Algorithm
can	O
be	O
obtained	O
by	O
taking	O
the	O
cycle	B-Algorithm
notation	I-Algorithm
for	O
and	O
applying	O
to	O
all	O
the	O
entries	O
in	O
it	O
.	O
</s>
<s>
It	O
is	O
the	O
least	O
common	O
multiple	O
of	O
its	O
cycles	B-Algorithm
lengths	O
.	O
</s>
<s>
Every	O
permutation	O
of	O
a	O
finite	O
set	O
can	O
be	O
expressed	O
as	O
the	O
product	O
of	O
transpositions	B-Algorithm
.	O
</s>
<s>
Although	O
many	O
such	O
expressions	O
for	O
a	O
given	O
permutation	O
may	O
exist	O
,	O
either	O
they	O
all	O
contain	O
an	O
even	O
number	O
of	O
transpositions	B-Algorithm
or	O
they	O
all	O
contain	O
an	O
odd	O
number	O
of	O
transpositions	B-Algorithm
.	O
</s>
<s>
There	O
is	O
a	O
relationship	O
between	O
the	O
one-line	O
notation	O
and	O
the	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
.	O
</s>
<s>
Consider	O
the	O
permutation	O
in	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
;	O
if	O
we	O
simply	O
remove	O
the	O
parentheses	O
,	O
we	O
obtain	O
the	O
permutation	O
in	O
one-line	O
notation	O
.	O
</s>
<s>
Foata	O
's	O
transition	O
lemma	O
establishes	O
the	O
nature	O
of	O
this	O
correspondence	O
as	O
a	O
bijection	B-Algorithm
on	O
the	O
set	O
of	O
n-permutations	O
(	O
to	O
itself	O
)	O
.	O
</s>
<s>
Richard	O
P	O
.	O
Stanley	O
calls	O
this	O
correspondence	O
the	O
fundamental	O
bijection	B-Algorithm
.	O
</s>
<s>
Let	O
be	O
the	O
parentheses-erasing	O
transformation	O
which	O
returns	O
in	O
one-line	O
notation	O
when	O
given	O
in	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
.	O
</s>
<s>
The	O
operation	O
of	O
the	O
inverse	O
transformation	O
,	O
,	O
which	O
returns	O
in	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
when	O
given	O
in	O
one-line	O
notation	O
,	O
is	O
a	O
bit	O
less	O
intuitive	O
.	O
</s>
<s>
Given	O
the	O
one-line	O
notation	O
,	O
the	O
first	O
cycle	O
of	O
in	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
must	O
start	O
with	O
.	O
</s>
<s>
Every	O
cycle	O
in	O
the	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
starts	O
with	O
a	O
left-to-right	O
maximum	O
.	O
</s>
<s>
Concatenating	O
these	O
4	O
cycles	B-Algorithm
gives	O
in	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
.	O
</s>
<s>
The	O
bold	O
side	O
of	O
each	O
equality	O
shows	O
the	O
permutation	O
using	O
its	O
designated	O
notation	O
(	O
one-line	O
notation	O
for	O
and	O
canonical	O
cycle	B-Algorithm
notation	I-Algorithm
for	O
)	O
while	O
the	O
non-bold	O
side	O
shows	O
the	O
same	O
permutation	O
in	O
the	O
other	O
notation	O
.	O
</s>
<s>
Comparing	O
the	O
bold	O
side	O
of	O
each	O
column	O
of	O
the	O
table	O
shows	O
the	O
parenthesis	O
removing/restoring	O
operation	O
of	O
Foata	O
's	O
bijection	B-Algorithm
,	O
while	O
comparing	O
the	O
same	O
side	O
of	O
each	O
column	O
(	O
for	O
example	O
,	O
the	O
LHS	O
)	O
shows	O
which	O
permutations	O
are	O
mapped	O
to	O
themselves	O
by	O
the	O
bijection	B-Algorithm
(	O
first	O
3	O
rows	O
)	O
and	O
which	O
are	O
not	O
(	O
last	O
3	O
rows	O
)	O
.	O
</s>
<s>
An	O
inversion	B-Algorithm
of	O
a	O
permutationσ	O
is	O
a	O
pair	O
of	O
positions	O
where	O
the	O
entries	O
of	O
a	O
permutation	O
are	O
in	O
the	O
opposite	O
order	O
:	O
and	O
.	O
</s>
<s>
So	O
a	O
descent	O
is	O
just	O
an	O
inversion	B-Algorithm
at	O
two	O
adjacent	O
positions	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
permutation	O
has	O
three	O
inversions	B-Algorithm
:	O
(	O
1	O
,	O
3	O
)	O
,	O
(	O
2	O
,	O
3	O
)	O
,	O
and	O
(	O
4	O
,	O
5	O
)	O
,	O
for	O
the	O
pairs	O
of	O
entries	O
(	O
2	O
,	O
1	O
)	O
,	O
(	O
3	O
,	O
1	O
)	O
,	O
and	O
(	O
5	O
,	O
4	O
)	O
.	O
</s>
<s>
Sometimes	O
an	O
inversion	B-Algorithm
is	O
defined	O
as	O
the	O
pair	O
of	O
values	O
whose	O
order	O
is	O
reversed	O
;	O
this	O
makes	O
no	O
difference	O
for	O
the	O
number	O
of	O
inversions	B-Algorithm
,	O
and	O
this	O
pair	O
(	O
reversed	O
)	O
is	O
also	O
an	O
inversion	B-Algorithm
in	O
the	O
above	O
sense	O
for	O
the	O
inverse	O
permutation	O
σ−1	O
.	O
</s>
<s>
The	O
number	O
of	O
inversions	B-Algorithm
is	O
an	O
important	O
measure	O
for	O
the	O
degree	O
to	O
which	O
the	O
entries	O
of	O
a	O
permutation	O
are	O
out	O
of	O
order	O
;	O
it	O
is	O
the	O
same	O
for	O
σ	O
and	O
for	O
σ−1	O
.	O
</s>
<s>
To	O
bring	O
a	O
permutation	O
with	O
k	O
inversions	B-Algorithm
into	O
order	O
(	O
that	O
is	O
,	O
transform	O
it	O
into	O
the	O
identity	O
permutation	O
)	O
,	O
by	O
successively	O
applying	O
(	O
right-multiplication	O
by	O
)	O
adjacent	O
transpositions	B-Algorithm
,	O
is	O
always	O
possible	O
and	O
requires	O
a	O
sequence	O
of	O
k	O
such	O
operations	O
.	O
</s>
<s>
Moreover	O
,	O
any	O
reasonable	O
choice	O
for	O
the	O
adjacent	O
transpositions	B-Algorithm
will	O
work	O
:	O
it	O
suffices	O
to	O
choose	O
at	O
each	O
step	O
a	O
transposition	B-Algorithm
of	O
i	O
and	O
where	O
i	O
is	O
a	O
descent	O
of	O
the	O
permutation	O
as	O
modified	O
so	O
far	O
(	O
so	O
that	O
the	O
transposition	B-Algorithm
will	O
remove	O
this	O
particular	O
descent	O
,	O
although	O
it	O
might	O
create	O
other	O
descents	O
)	O
.	O
</s>
<s>
This	O
is	O
so	O
because	O
applying	O
such	O
a	O
transposition	B-Algorithm
reduces	O
the	O
number	O
of	O
inversions	B-Algorithm
by1	O
;	O
as	O
long	O
as	O
this	O
number	O
is	O
not	O
zero	O
,	O
the	O
permutation	O
is	O
not	O
the	O
identity	O
,	O
so	O
it	O
has	O
at	O
least	O
one	O
descent	O
.	O
</s>
<s>
Bubble	B-Algorithm
sort	I-Algorithm
and	O
insertion	B-Algorithm
sort	I-Algorithm
can	O
be	O
interpreted	O
as	O
particular	O
instances	O
of	O
this	O
procedure	O
to	O
put	O
a	O
sequence	O
into	O
order	O
.	O
</s>
<s>
Incidentally	O
this	O
procedure	O
proves	O
that	O
any	O
permutation	O
σ	O
can	O
be	O
written	O
as	O
a	O
product	O
of	O
adjacent	O
transpositions	B-Algorithm
;	O
for	O
this	O
one	O
may	O
simply	O
reverse	O
any	O
sequence	O
of	O
such	O
transpositions	B-Algorithm
that	O
transforms	O
σ	O
into	O
the	O
identity	O
.	O
</s>
<s>
In	O
fact	O
,	O
by	O
enumerating	O
all	O
sequences	O
of	O
adjacent	O
transpositions	B-Algorithm
that	O
would	O
transform	O
σ	O
into	O
the	O
identity	O
,	O
one	O
obtains	O
(	O
after	O
reversal	O
)	O
a	O
complete	O
list	O
of	O
all	O
expressions	O
of	O
minimal	O
length	O
writing	O
σ	O
as	O
a	O
product	O
of	O
adjacent	O
transpositions	B-Algorithm
.	O
</s>
<s>
In	O
this	O
case	O
,	O
say	O
the	O
weight	O
of	O
the	O
inversion	B-Algorithm
is	O
.	O
</s>
<s>
where	O
denotes	O
Bruhat	O
order	O
in	O
the	O
symmetric	B-Algorithm
groups	I-Algorithm
.	O
</s>
<s>
The	O
second	O
step	O
interprets	O
this	O
sequence	O
as	O
a	O
Lehmer	O
code	O
or	O
(	O
almost	O
equivalently	O
)	O
as	O
an	O
inversion	B-Algorithm
table	O
.	O
</s>
<s>
Since	O
those	O
remaining	O
elements	O
are	O
bound	O
to	O
turn	O
up	O
as	O
some	O
later	O
term	O
σj	O
,	O
the	O
digit	O
dn+1−i	O
counts	O
the	O
inversions	B-Algorithm
(	O
i	O
,	O
j	O
)	O
involving	O
i	O
as	O
smaller	O
index	O
(	O
the	O
number	O
of	O
values	O
j	O
for	O
which	O
ij	O
and	O
σiσj	O
)	O
.	O
</s>
<s>
The	O
inversion	B-Algorithm
table	O
forσ	O
is	O
quite	O
similar	O
,	O
but	O
here	O
dn+1−k	O
counts	O
the	O
number	O
of	O
inversions	B-Algorithm
(	O
i	O
,	O
j	O
)	O
where	O
k	O
=	O
σj	O
occurs	O
as	O
the	O
smaller	O
of	O
the	O
two	O
values	O
appearing	O
in	O
inverted	O
order	O
.	O
</s>
<s>
Both	O
encodings	O
can	O
be	O
visualized	O
by	O
an	O
nbyn	O
Rothe	O
diagram	O
(	O
named	O
after	O
Heinrich	O
August	O
Rothe	O
)	O
in	O
which	O
dots	O
at	O
(	O
i	O
,	O
σi	O
)	O
mark	O
the	O
entries	O
of	O
the	O
permutation	O
,	O
and	O
a	O
cross	O
at	O
(	O
i	O
,	O
σj	O
)	O
marks	O
the	O
inversion	B-Algorithm
(	O
i	O
,	O
j	O
)	O
;	O
by	O
the	O
definition	O
of	O
inversions	B-Algorithm
a	O
cross	O
appears	O
in	O
any	O
square	O
that	O
comes	O
both	O
before	O
the	O
dot	O
(	O
j	O
,	O
σj	O
)	O
in	O
its	O
column	O
,	O
and	O
before	O
the	O
dot	O
(	O
i	O
,	O
σi	O
)	O
in	O
its	O
row	O
.	O
</s>
<s>
The	O
Lehmer	O
code	O
lists	O
the	O
numbers	O
of	O
crosses	O
in	O
successive	O
rows	O
,	O
while	O
the	O
inversion	B-Algorithm
table	O
lists	O
the	O
numbers	O
of	O
crosses	O
in	O
successive	O
columns	O
;	O
it	O
is	O
just	O
the	O
Lehmer	O
code	O
for	O
the	O
inverse	O
permutation	O
,	O
and	O
vice	O
versa	O
.	O
</s>
<s>
To	O
convert	O
an	O
inversion	B-Algorithm
table	O
dn	O
,	O
dn−1	O
,	O
...	O
,	O
d2	O
,	O
d1	O
into	O
the	O
corresponding	O
permutation	O
,	O
one	O
can	O
traverse	O
the	O
numbers	O
from	O
d1	O
to	O
dn	O
while	O
inserting	O
the	O
elements	O
of	O
S	O
from	O
largest	O
to	O
smallest	O
into	O
an	O
initially	O
empty	O
sequence	O
;	O
at	O
the	O
step	O
using	O
the	O
number	O
d	O
from	O
the	O
inversion	B-Algorithm
table	O
,	O
the	O
element	O
from	O
S	O
inserted	O
into	O
the	O
sequence	O
at	O
the	O
point	O
where	O
it	O
is	O
preceded	O
by	O
d	O
elements	O
already	O
present	O
.	O
</s>
<s>
Alternatively	O
one	O
could	O
process	O
the	O
numbers	O
from	O
the	O
inversion	B-Algorithm
table	O
and	O
the	O
elements	O
of	O
S	O
both	O
in	O
the	O
opposite	O
order	O
,	O
starting	O
with	O
a	O
row	O
of	O
n	O
empty	O
slots	O
,	O
and	O
at	O
each	O
step	O
place	O
the	O
element	O
from	O
S	O
into	O
the	O
empty	O
slot	O
that	O
is	O
preceded	O
by	O
d	O
other	O
empty	O
slots	O
.	O
</s>
<s>
Converting	O
successive	O
natural	O
numbers	O
to	O
the	O
factorial	O
number	O
system	O
produces	O
those	O
sequences	O
in	O
lexicographic	O
order	O
(	O
as	O
is	O
the	O
case	O
with	O
any	O
mixed	O
radix	O
number	O
system	O
)	O
,	O
and	O
further	O
converting	O
them	O
to	O
permutations	O
preserves	O
the	O
lexicographic	O
ordering	O
,	O
provided	O
the	O
Lehmer	O
code	O
interpretation	O
is	O
used	O
(	O
using	O
inversion	B-Algorithm
tables	O
,	O
one	O
gets	O
a	O
different	O
ordering	O
,	O
where	O
one	O
starts	O
by	O
comparing	O
permutations	O
by	O
the	O
place	O
of	O
their	O
entries	O
1	O
rather	O
than	O
by	O
the	O
value	O
of	O
their	O
first	O
entries	O
)	O
.	O
</s>
<s>
The	O
sum	O
of	O
the	O
numbers	O
in	O
the	O
factorial	O
number	O
system	O
representation	O
gives	O
the	O
number	O
of	O
inversions	B-Algorithm
of	O
the	O
permutation	O
,	O
and	O
the	O
parity	O
of	O
that	O
sum	O
gives	O
the	O
signature	O
of	O
the	O
permutation	O
.	O
</s>
<s>
Moreover	O
,	O
the	O
positions	O
of	O
the	O
zeroes	O
in	O
the	O
inversion	B-Algorithm
table	O
give	O
the	O
values	O
of	O
left-to-right	O
maxima	O
of	O
the	O
permutation	O
(	O
in	O
the	O
example	O
6	O
,	O
8	O
,	O
9	O
)	O
while	O
the	O
positions	O
of	O
the	O
zeroes	O
in	O
the	O
Lehmer	O
code	O
are	O
the	O
positions	O
of	O
the	O
right-to-left	O
minima	O
(	O
in	O
the	O
example	O
positions	O
the	O
4	O
,	O
8	O
,	O
9	O
of	O
the	O
values	O
1	O
,	O
2	O
,	O
5	O
)	O
;	O
this	O
allows	O
computing	O
the	O
distribution	O
of	O
such	O
extrema	O
among	O
all	O
permutations	O
.	O
</s>
<s>
Another	O
question	O
is	O
whether	O
possible	O
equality	O
among	O
entries	O
in	O
the	O
given	O
sequence	O
is	O
to	O
be	O
taken	O
into	O
account	O
;	O
if	O
so	O
,	O
one	O
should	O
only	O
generate	O
distinct	O
multiset	B-Language
permutations	O
of	O
the	O
sequence	O
.	O
</s>
<s>
However	O
,	O
the	O
latter	O
step	O
,	O
while	O
straightforward	O
,	O
is	O
hard	O
to	O
implement	O
efficiently	O
,	O
because	O
it	O
requires	O
n	O
operations	O
each	O
of	O
selection	O
from	O
a	O
sequence	O
and	O
deletion	O
from	O
it	O
,	O
at	O
an	O
arbitrary	O
position	O
;	O
of	O
the	O
obvious	O
representations	O
of	O
the	O
sequence	O
as	O
an	O
array	B-Data_Structure
or	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
both	O
require	O
(	O
for	O
different	O
reasons	O
)	O
about	O
n2/4	O
operations	O
to	O
perform	O
the	O
conversion	O
.	O
</s>
<s>
For	O
generating	O
random	B-Algorithm
permutations	I-Algorithm
of	O
a	O
given	O
sequence	O
of	O
n	O
values	O
,	O
it	O
makes	O
no	O
difference	O
whether	O
one	O
applies	O
a	O
randomly	O
selected	O
permutation	O
of	O
n	O
to	O
the	O
sequence	O
,	O
or	O
chooses	O
a	O
random	O
element	O
from	O
the	O
set	O
of	O
distinct	O
(	O
multiset	B-Language
)	O
permutations	O
of	O
the	O
sequence	O
.	O
</s>
<s>
The	O
basic	O
idea	O
to	O
generate	O
a	O
random	B-Algorithm
permutation	I-Algorithm
is	O
to	O
generate	O
at	O
random	O
one	O
of	O
the	O
n	O
!	O
</s>
<s>
sequences	O
of	O
integers	O
d1	O
,	O
d2	O
,...,	O
dn	O
satisfying	O
(	O
since	O
d1	O
is	O
always	O
zero	O
it	O
may	O
be	O
omitted	O
)	O
and	O
to	O
convert	O
it	O
to	O
a	O
permutation	O
through	O
a	O
bijective	B-Algorithm
correspondence	O
.	O
</s>
<s>
This	O
can	O
be	O
remedied	O
by	O
using	O
a	O
different	O
bijective	B-Algorithm
correspondence	O
:	O
after	O
using	O
di	O
to	O
select	O
an	O
element	O
among	O
i	O
remaining	O
elements	O
of	O
the	O
sequence	O
(	O
for	O
decreasing	O
values	O
of	O
i	O
)	O
,	O
rather	O
than	O
removing	O
the	O
element	O
and	O
compacting	O
the	O
sequence	O
by	O
shifting	O
down	O
further	O
elements	O
one	O
place	O
,	O
one	O
swaps	O
the	O
element	O
with	O
the	O
final	O
remaining	O
element	O
.	O
</s>
<s>
The	O
mapping	O
from	O
sequence	O
of	O
integers	O
to	O
permutations	O
is	O
somewhat	O
complicated	O
,	O
but	O
it	O
can	O
be	O
seen	O
to	O
produce	O
each	O
permutation	O
in	O
exactly	O
one	O
way	O
,	O
by	O
an	O
immediate	O
induction	B-Algorithm
.	O
</s>
<s>
The	O
resulting	O
algorithm	O
for	O
generating	O
a	O
random	B-Algorithm
permutation	I-Algorithm
of	O
a[0],	O
a[1],	O
...	O
,	O
a[ n	O
−	O
1 ]	O
can	O
be	O
described	O
as	O
follows	O
in	O
pseudocode	B-Language
:	O
</s>
<s>
It	O
can	O
handle	O
repeated	O
values	O
,	O
for	O
which	O
case	O
it	O
generates	O
each	O
distinct	O
multiset	B-Language
permutation	O
once	O
.	O
</s>
<s>
It	O
begins	O
by	O
sorting	B-Algorithm
the	O
sequence	O
in	O
(	O
weakly	O
)	O
increasing	O
order	O
(	O
which	O
gives	O
its	O
lexicographically	O
minimal	O
permutation	O
)	O
,	O
and	O
then	O
repeats	O
advancing	O
to	O
the	O
next	O
permutation	O
as	O
long	O
as	O
one	O
is	O
found	O
.	O
</s>
<s>
An	O
alternative	O
to	O
the	O
above	O
algorithm	O
,	O
the	O
Steinhaus	B-Algorithm
–	I-Algorithm
Johnson	I-Algorithm
–	I-Algorithm
Trotter	I-Algorithm
algorithm	I-Algorithm
,	O
generates	O
an	O
ordering	O
on	O
all	O
the	O
permutations	O
of	O
a	O
given	O
sequence	O
with	O
the	O
property	O
that	O
any	O
two	O
consecutive	O
permutations	O
in	O
its	O
output	O
differ	O
by	O
swapping	O
two	O
adjacent	O
values	O
.	O
</s>
<s>
This	O
ordering	O
on	O
the	O
permutations	O
was	O
known	O
to	O
17th-century	O
English	O
bell	O
ringers	O
,	O
among	O
whom	O
it	O
was	O
known	O
as	O
"	O
plain	B-Algorithm
changes	I-Algorithm
"	O
.	O
</s>
<s>
An	O
alternative	O
to	O
Steinhaus	O
–	O
Johnson	B-Algorithm
–	I-Algorithm
Trotter	I-Algorithm
is	O
Heap	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
said	O
by	O
Robert	O
Sedgewick	O
in	O
1977	O
to	O
be	O
the	O
fastest	O
algorithm	O
of	O
generating	O
permutations	O
in	O
applications	O
.	O
</s>
<s>
Steinhaus	B-Algorithm
–	I-Algorithm
Johnson	I-Algorithm
–	I-Algorithm
Trotter	I-Algorithm
algorithm	I-Algorithm
;	O
</s>
<s>
Heap	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
;	O
</s>
<s>
Ehrlich	O
's	O
star-transposition	O
algorithm	O
:	O
in	O
each	O
step	O
,	O
the	O
first	O
entry	O
of	O
the	O
permutation	O
is	O
exchanged	O
with	O
a	O
later	O
entry	O
;	O
</s>
<s>
Single-track	O
Gray	O
code	O
:	O
each	O
column	O
is	O
a	O
cyclic	O
shift	O
of	O
the	O
other	O
columns	O
,	O
plus	O
any	O
two	O
consecutive	O
permutations	O
differ	O
only	O
in	O
one	O
or	O
two	O
transpositions	B-Algorithm
.	O
</s>
<s>
An	O
alternate	O
permutation	O
of	O
the	O
set	O
{	O
1	O
,	O
2	O
,	O
...	O
,	O
2n}	O
is	O
a	O
cyclic	B-Algorithm
permutation	I-Algorithm
(	O
with	O
no	O
fixed	O
points	O
)	O
such	O
that	O
the	O
digits	O
in	O
the	O
cyclic	O
notation	O
form	O
alternate	O
between	O
odd	O
and	O
even	O
integers	O
.	O
</s>
<s>
A	O
modification	O
of	O
Heap	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
has	O
been	O
used	O
to	O
generate	O
all	O
alternate	O
permutations	O
of	O
order	O
n	O
(	O
that	O
is	O
,	O
of	O
length	O
2n	O
)	O
without	O
generating	O
all	O
(	O
2n	O
)	O
!	O
</s>
<s>
Three	O
copies	O
of	O
each	O
of	O
these	O
have	O
a	O
"	O
6	O
"	O
added	O
to	O
the	O
right	O
end	O
,	O
and	O
then	O
a	O
different	O
transposition	B-Algorithm
involving	O
this	O
last	O
entry	O
and	O
a	O
previous	O
entry	O
in	O
an	O
even	O
position	O
is	O
applied	O
(	O
including	O
the	O
identity	O
;	O
that	O
is	O
,	O
no	O
transposition	B-Algorithm
)	O
.	O
</s>
<s>
Permutations	O
are	O
used	O
in	O
the	O
interleaver	O
component	O
of	O
the	O
error	B-Error_Name
detection	I-Error_Name
and	I-Error_Name
correction	I-Error_Name
algorithms	O
,	O
such	O
as	O
turbo	B-Error_Name
codes	I-Error_Name
,	O
for	O
example	O
3GPP	O
Long	O
Term	O
Evolution	O
mobile	O
telecommunication	O
standard	O
uses	O
these	O
ideas	O
(	O
see	O
3GPP	O
technical	O
specification	O
36.212	O
)	O
.	O
</s>
<s>
One	O
of	O
the	O
methods	O
is	O
based	O
on	O
the	O
permutation	B-Algorithm
polynomials	I-Algorithm
.	O
</s>
