Inversion (discrete mathematics)

Last updated
Permutation with one of its inversions highlighted. An inversion may be denoted by the pair of places (2, 4) or the pair of elements (5, 2). The inversions of this permutation using element-based notation are: (3, 1), (3, 2), (5, 1), (5, 2), and (5,4). Inversion qtl1.svg
Permutation with one of its inversions highlighted. An inversion may be denoted by the pair of places (2, 4) or the pair of elements (5, 2). The inversions of this permutation using element-based notation are: (3, 1), (3, 2), (5, 1), (5, 2), and (5,4).

In computer science and discrete mathematics, an inversion in a sequence is a pair of elements that are out of their natural order.

Contents

Definitions

Inversion

Let be a permutation. There is an inversion of between and if and . The inversion is indicated by an ordered pair containing either the places [1] [2] or the elements [3] [4] [5] .

The inversion set is the set of all inversions. A permutation's inversion set using place-based notation is the same as the inverse permutation's inversion set using element-based notation with the two components of each ordered pair exchanged. Likewise, a permutation's inversion set using element-based notation is the same as the inverse permutation's inversion set using place-based notation with the two components of each ordered pair exchanged. [6]

Inversions are usually defined for permutations, but may also be defined for sequences:
Let be a sequence (or multiset permutation [7] ). If and , either the pair of places [7] [8] or the pair of elements [9] is called an inversion of .

For sequences, inversions according to the element-based definition are not unique, because different pairs of places may have the same pair of values.

Inversion number

The inversion number [10] of a sequence , is the cardinality of the inversion set. It is a common measure of sortedness (sometimes called presortedness) of a permutation [5] or sequence. [9] The inversion number is between 0 and inclusive. A permutation and its inverse have the same inversion number.

For example since the sequence is ordered. Also, when is even, (because each pair is an inversion). This last example shows that a set that is intuitively "nearly sorted" can still have a quadratic number of inversions.

The inversion number is the number of crossings in the arrow diagram of the permutation, [6] the permutation's Kendall tau distance from the identity permutation, and the sum of each of the inversion related vectors defined below.

Other measures of sortedness include the minimum number of elements that can be deleted from the sequence to yield a fully sorted sequence, the number and lengths of sorted "runs" within the sequence, the Spearman footrule (sum of distances of each element from its sorted position), and the smallest number of exchanges needed to sort the sequence. [11] Standard comparison sorting algorithms can be adapted to compute the inversion number in time O(n log n). [12]

Three similar vectors are in use that condense the inversions of a permutation into a vector that uniquely determines it. They are often called inversion vector or Lehmer code . (A list of sources is found here.)

This article uses the term inversion vector () like Wolfram. [13] The remaining two vectors are sometimes called left and right inversion vector, but to avoid confusion with the inversion vector this article calls them left inversion count () and right inversion count (). Interpreted as a factorial number the left inversion count gives the permutations reverse colexicographic, [14] and the right inversion count gives the lexicographic index.

Rothe diagram Inversion example; Rothe 1.svg
Rothe diagram

Inversion vector :
With the element-based definition is the number of inversions whose smaller (right) component is . [3]

is the number of elements in greater than before .

Left inversion count :
With the place-based definition is the number of inversions whose bigger (right) component is .

is the number of elements in greater than before .

Right inversion count , often called Lehmer code :
With the place-based definition is the number of inversions whose smaller (left) component is .

is the number of elements in smaller than after .

Both and can be found with the help of a Rothe diagram, which is a permutation matrix with the 1s represented by dots, and an inversion (often represented by a cross) in every position that has a dot to the right and below it. is the sum of inversions in row of the Rothe diagram, while is the sum of inversions in column . The permutation matrix of the inverse is the transpose, therefore of a permutation is of its inverse, and vice versa.

Example: All permutations of four elements

The six possible inversions of a 4-element permutation 2-element subsets of 4 elements; array, hexagonal.svg
The six possible inversions of a 4-element permutation

The following sortable table shows the 24 permutations of four elements (in the column) with their place-based inversion sets (in the p-b column), inversion related vectors (in the , , and columns), and inversion numbers (in the # column). (The columns with smaller print and no heading are reflections of the columns next to them, and can be used to sort them in colexicographic order.)

It can be seen that and always have the same digits, and that and are both related to the place-based inversion set. The nontrivial elements of are the sums of the descending diagonals of the shown triangle, and those of are the sums of the ascending diagonals. (Pairs in descending diagonals have the right components 2, 3, 4 in common, while pairs in ascending diagonals have the left components 1, 2, 3 in common.)

The default order of the table is reverse colex order by , which is the same as colex order by . Lex order by is the same as lex order by .

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
p-b#
0 4-el perm matrix 00.svg 123443210000000000000000 4-el perm invset 00.svg 000000000
1 4-el perm matrix 01.svg 213443121000000100100100 4-el perm invset 01.svg 100000011
2 4-el perm matrix 02.svg 132442310100001001000010 4-el perm invset 02.svg 010000101
3 4-el perm matrix 03.svg 312442131100001101100110 4-el perm invset 03.svg 200000022
4 4-el perm matrix 04.svg 231441322000000202000020 4-el perm invset 04.svg 110000112
5 4-el perm matrix 05.svg 321441232100001202100120 4-el perm invset 05.svg 210000123
6 4-el perm matrix 06.svg 124334210010010010000001 4-el perm invset 06.svg 001001001
7 4-el perm matrix 07.svg 214334121010010110100101 4-el perm invset 07.svg 101001012
8 4-el perm matrix 08.svg 142332410110011011000011 4-el perm invset 08.svg 020000202
9 4-el perm matrix 09.svg 412332141110011111100111 4-el perm invset 09.svg 300000033
10 4-el perm matrix 10.svg 241331422010010212000021 4-el perm invset 10.svg 120000213
11 4-el perm matrix 11.svg 421331242110011212100121 4-el perm invset 11.svg 310000134
12 4-el perm matrix 12.svg 134224310200002020000002 4-el perm invset 12.svg 011001102
13 4-el perm matrix 13.svg 314224131200002120100102 4-el perm invset 13.svg 201001023
14 4-el perm matrix 14.svg 143223410210012021000012 4-el perm invset 14.svg 021001203
15 4-el perm matrix 15.svg 413223141210012121100112 4-el perm invset 15.svg 301001034
16 4-el perm matrix 16.svg 341221432200002222000022 4-el perm invset 16.svg 220000224
17 4-el perm matrix 17.svg 431221342210012222100122 4-el perm invset 17.svg 320000235
18 4-el perm matrix 18.svg 234114323000000330000003 4-el perm invset 18.svg 111001113
19 4-el perm matrix 19.svg 324114233100001330100103 4-el perm invset 19.svg 211001124
20 4-el perm matrix 20.svg 243113423010010331000013 4-el perm invset 20.svg 121001214
21 4-el perm matrix 21.svg 423113243110011331100113 4-el perm invset 21.svg 311001135
22 4-el perm matrix 22.svg 342112433200002332000023 4-el perm invset 22.svg 221001225
23 4-el perm matrix 23.svg 432112343210012332100123 4-el perm invset 23.svg 321001236

Weak order of permutations

Permutohedron of the symmetric group S4 Symmetric group 4; permutohedron 3D; numbers.svg
Permutohedron of the symmetric group S4

The set of permutations on n items can be given the structure of a partial order, called the weak order of permutations, which forms a lattice.

The Hasse diagram of the inversion sets ordered by the subset relation forms the skeleton of a permutohedron.

If a permutation is assigned to each inversion set using the place-based definition, the resulting order of permutations is that of the permutohedron, where an edge corresponds to the swapping of two elements with consecutive values. This is the weak order of permutations. The identity is its minimum, and the permutation formed by reversing the identity is its maximum.

If a permutation were assigned to each inversion set using the element-based definition, the resulting order of permutations would be that of a Cayley graph, where an edge corresponds to the swapping of two elements on consecutive places. This Cayley graph of the symmetric group is similar to its permutohedron, but with each permutation replaced by its inverse.

See also

Sequences in the OEIS:

Related Research Articles

<span class="mw-page-title-main">Discrete Fourier transform</span> Type of Fourier transform in discrete mathematics

In mathematics, the discrete Fourier transform (DFT) converts a finite sequence of equally-spaced samples of a function into a same-length sequence of equally-spaced samples of the discrete-time Fourier transform (DTFT), which is a complex-valued function of frequency. The interval at which the DTFT is sampled is the reciprocal of the duration of the input sequence. An inverse DFT is a Fourier series, using the DTFT samples as coefficients of complex sinusoids at the corresponding DTFT frequencies. It has the same sample-values as the original input sequence. The DFT is therefore said to be a frequency domain representation of the original input sequence. If the original sequence spans all the non-zero values of a function, its DTFT is continuous, and the DFT provides discrete samples of one cycle. If the original sequence is one cycle of a periodic function, the DFT provides all the non-zero values of one DTFT cycle.

<span class="mw-page-title-main">Permutation group</span> Group whose operation is composition of permutations

In mathematics, a permutation group is a group G whose elements are permutations of a given set M and whose group operation is the composition of permutations in G. The group of all permutations of a set M is the symmetric group of M, often written as Sym(M). The term permutation group thus means a subgroup of the symmetric group. If M = {1, 2, ..., n} then Sym(M) is usually denoted by Sn, and may be called the symmetric group on n letters.

<span class="mw-page-title-main">Simplex</span> Multi-dimensional generalization of triangle

In geometry, a simplex is a generalization of the notion of a triangle or tetrahedron to arbitrary dimensions. The simplex is so-named because it represents the simplest possible polytope made with line segments in any given dimension.

<span class="mw-page-title-main">Permutation</span> Mathematical version of an order change

In mathematics, a permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word "permutation" also refers to the act or process of changing the linear order of an ordered set.

In mathematics, when X is a finite set with at least two elements, the permutations of X fall into two classes of equal size: the even permutations and the odd permutations. If any total ordering of X is fixed, the parity of a permutation of X can be defined as the parity of the number of inversions for σ, i.e., of pairs of elements x, y of X such that x < y and σ(x) > σ(y).

<span class="mw-page-title-main">Shellsort</span> Sorting algorithm which uses multiple comparison intervals

Shellsort, also known as Shell sort or Shell's method, is an in-place comparison sort. It can be seen as either a generalization of sorting by exchange or sorting by insertion. The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. By starting with far apart elements, it can move some out-of-place elements into position faster than a simple nearest neighbor exchange. Donald Shell published the first version of this sort in 1959. The running time of Shellsort is heavily dependent on the gap sequence it uses. For many practical variants, determining their time complexity remains an open problem.

A discrete Hartley transform (DHT) is a Fourier-related transform of discrete, periodic data similar to the discrete Fourier transform (DFT), with analogous applications in signal processing and related fields. Its main distinction from the DFT is that it transforms real inputs to real outputs, with no intrinsic involvement of complex numbers. Just as the DFT is the discrete analogue of the continuous Fourier transform (FT), the DHT is the discrete analogue of the continuous Hartley transform (HT), introduced by Ralph V. L. Hartley in 1942.

In mathematics, particularly in matrix theory, a permutation matrix is a square binary matrix that has exactly one entry of 1 in each row and each column and 0s elsewhere. Each such matrix, say P, represents a permutation of m elements and, when used to multiply another matrix, say A, results in permuting the rows or columns of the matrix A.

The Cooley–Tukey algorithm, named after J. W. Cooley and John Tukey, is the most common fast Fourier transform (FFT) algorithm. It re-expresses the discrete Fourier transform (DFT) of an arbitrary composite size in terms of N1 smaller DFTs of sizes N2, recursively, to reduce the computation time to O(N log N) for highly composite N. Because of the algorithm's importance, specific variants and implementation styles have become known by their own names, as described below.

In mathematics, and in particular in group theory, a cyclic permutation is a permutation of the elements of some set X which maps the elements of some subset S of X to each other in a cyclic fashion, while fixing all other elements of X. If S has k elements, the cycle is called a k-cycle. Cycles are often denoted by the list of their elements enclosed with parentheses, in the order to which they are permuted.

In linear algebra, a tridiagonal matrix is a band matrix that has nonzero elements only on the main diagonal, the subdiagonal/lower diagonal, and the supradiagonal/upper diagonal . For example, the following matrix is tridiagonal:

<span class="mw-page-title-main">Steinhaus–Johnson–Trotter algorithm</span>

The Steinhaus–Johnson–Trotter algorithm or Johnson–Trotter algorithm, also called plain changes, is an algorithm named after Hugo Steinhaus, Selmer M. Johnson and Hale F. Trotter that generates all of the permutations of elements. Each permutation in the sequence that it generates differs from the previous permutation by swapping two adjacent elements of the sequence. Equivalently, this algorithm finds a Hamiltonian cycle in the permutohedron.

A logical matrix, binary matrix, relation matrix, Boolean matrix, or (0, 1) matrix is a matrix with entries from the Boolean domain B = {0, 1}. Such a matrix can be used to represent a binary relation between a pair of finite sets.

<span class="mw-page-title-main">Permutation graph</span> Graph representing a permutation

In the mathematical field of graph theory, a permutation graph is a graph whose vertices represent the elements of a permutation, and whose edges represent pairs of elements that are reversed by the permutation. Permutation graphs may also be defined geometrically, as the intersection graphs of line segments whose endpoints lie on two parallel lines. Different permutations may give rise to the same permutation graph; a given graph has a unique representation if it is prime with respect to the modular decomposition.

In mathematics, the Robinson–Schensted–Knuth correspondence, also referred to as the RSK correspondence or RSK algorithm, is a combinatorial bijection between matrices A with non-negative integer entries and pairs (P,Q) of semistandard Young tableaux of equal shape, whose size equals the sum of the entries of A. More precisely the weight of P is given by the column sums of A, and the weight of Q by its row sums. It is a generalization of the Robinson–Schensted correspondence, in the sense that taking A to be a permutation matrix, the pair (P,Q) will be the pair of standard tableaux associated to the permutation under the Robinson–Schensted correspondence.

In combinatorial mathematics and theoretical computer science, a permutation pattern is a sub-permutation of a longer permutation. Any permutation may be written in one-line notation as a sequence of digits representing the result of applying the permutation to the digit sequence 123...; for instance the digit sequence 213 represents the permutation on three elements that swaps elements 1 and 2. If π and σ are two permutations represented in this way, then π is said to contain σ as a pattern if some subsequence of the digits of π has the same relative order as all of the digits of σ.

In mathematics and in particular in combinatorics, the Lehmer code is a particular way to encode each possible permutation of a sequence of n numbers. It is an instance of a scheme for numbering permutations and is an example of an inversion table.

A Gilbreath shuffle is a way to shuffle a deck of cards, named after mathematician Norman Gilbreath. Gilbreath's principle describes the properties of a deck that are preserved by this type of shuffle, and a Gilbreath permutation is a permutation that can be formed by a Gilbreath shuffle.

In mathematics and computer science, a stack-sortable permutation is a permutation whose elements may be sorted by an algorithm whose internal storage is limited to a single stack data structure. The stack-sortable permutations are exactly the permutations that do not contain the permutation pattern 231; they are counted by the Catalan numbers, and may be placed in bijection with many other combinatorial objects with the same counting function including Dyck paths and binary trees.

<span class="mw-page-title-main">Affine symmetric group</span> Mathematical structure

The affine symmetric groups are a family of mathematical structures that describe the symmetries of the number line and the regular triangular tiling of the plane, as well as related higher-dimensional objects. Each one is an infinite extension of a finite symmetric group, the group of permutations (rearrangements) of a finite set. In addition to their geometric description, the affine symmetric groups may be defined as collections of permutations of the integers that are periodic in a certain sense, or in purely algebraic terms as a group with certain generators and relations. They are studied as part of the fields of combinatorics and representation theory.

References

  1. Aigner 2007, pp. 27.
  2. Comtet 1974, pp. 237.
  3. 1 2 Knuth 1973, pp. 11.
  4. Pemmaraju & Skiena 2003, pp. 69.
  5. 1 2 Vitter & Flajolet 1990, pp. 459.
  6. 1 2 Gratzer 2016, pp. 221.
  7. 1 2 Bóna 2012, pp. 57.
  8. Cormen et al. 2001, pp. 39.
  9. 1 2 Barth & Mutzel 2004, pp. 183.
  10. Mannila 1985.
  11. Mahmoud 2000, pp. 284.
  12. Kleinberg & Tardos 2005, pp. 225.
  13. Weisstein, Eric W. "Inversion Vector" From MathWorld--A Wolfram Web Resource
  14. Reverse colex order of finitary permutations (sequence A055089 in the OEIS )

Source bibliography

  • Aigner, Martin (2007). "Word Representation". A course in enumeration. Berlin, New York: Springer. ISBN   978-3642072536.
  • Barth, Wilhelm; Mutzel, Petra (2004). "Simple and Efficient Bilayer Cross Counting". Journal of Graph Algorithms and Applications . 8 (2): 179–194. doi: 10.7155/jgaa.00088 .
  • Bóna, Miklós (2012). "2.2 Inversions in Permutations of Multisets". Combinatorics of permutations. Boca Raton, FL: CRC Press. ISBN   978-1439850510.
  • Comtet, Louis (1974). "6.4 Inversions of a permutation of [n]". Advanced combinatorics; the art of finite and infinite expansions. Dordrecht,Boston: D. Reidel Pub. Co. ISBN   9027704414.
  • Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2001). Introduction to Algorithms (2nd ed.). MIT Press and McGraw-Hill. ISBN   0-262-53196-8.
  • Gratzer, George (2016). "7-2 Basic objects". Lattice theory. special topics and applications. Cham, Switzerland: Birkhäuser. ISBN   978-3319442358.
  • Kleinberg, Jon; Tardos, Éva (2005). Algorithm Design. ISBN   0-321-29535-8.
  • Knuth, Donald (1973). "5.1.1 Inversions". The Art of Computer Programming . Addison-Wesley Pub. Co. ISBN   0201896850.
  • Mahmoud, Hosam Mahmoud (2000). "Sorting Nonrandom Data". Sorting: a distribution theory. Wiley-Interscience series in discrete mathematics and optimization. Vol. 54. Wiley-IEEE. ISBN   978-0-471-32710-3.
  • Pemmaraju, Sriram V.; Skiena, Steven S. (2003). "Permutations and combinations". Computational discrete mathematics: combinatorics and graph theory with Mathematica. Cambridge University Press. ISBN   978-0-521-80686-2.
  • Vitter, J.S.; Flajolet, Ph. (1990). "Average-Case Analysis of Algorithms and Data Structures". In van Leeuwen, Jan (ed.). Algorithms and Complexity. Vol. 1 (2nd ed.). Elsevier. ISBN   978-0-444-88071-0.

Further reading

  • Margolius, Barbara H. (2001). "Permutations with Inversions". Journal of Integer Sequences. 4.

Presortedness measures