Menu
Home Explore People Places Arts History Plants & Animals Science Life & Culture Technology
On this page
Inversion (discrete mathematics)
Pair of positions in a sequence where two elements are out of sorted order

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

Related Image Collections Add Image
We don't have any YouTube videos related to Inversion (discrete mathematics) yet.
We don't have any PDF documents related to Inversion (discrete mathematics) yet.
We don't have any Books related to Inversion (discrete mathematics) yet.
We don't have any archived web articles related to Inversion (discrete mathematics) yet.

Definitions

Inversion

Let π {\displaystyle \pi } be a permutation. There is an inversion of π {\displaystyle \pi } between i {\displaystyle i} and j {\displaystyle j} if i < j {\displaystyle i<j} and π ( i ) > π ( j ) {\displaystyle \pi (i)>\pi (j)} . The inversion is indicated by an ordered pair containing either the places ( i , j ) {\displaystyle (i,j)} 12 or the elements ( π ( i ) , π ( j ) ) {\displaystyle {\bigl (}\pi (i),\pi (j){\bigr )}} .345

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 S {\displaystyle S} be a sequence (or multiset permutation7). If i < j {\displaystyle i<j} and S ( i ) > S ( j ) {\displaystyle S(i)>S(j)} , either the pair of places ( i , j ) {\displaystyle (i,j)} 89 or the pair of elements ( S ( i ) , S ( j ) ) {\displaystyle {\bigl (}S(i),S(j){\bigr )}} 10 is called an inversion of S {\displaystyle S} .

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 i n v ( X ) {\displaystyle {\mathtt {inv}}(X)} 11 of a sequence X = ⟨ x 1 , … , x n ⟩ {\displaystyle X=\langle x_{1},\dots ,x_{n}\rangle } , is the cardinality of the inversion set. It is a common measure of sortedness (sometimes called presortedness) of a permutation12 or sequence.13 The inversion number is between 0 and n ( n − 1 ) 2 {\displaystyle {\frac {n(n-1)}{2}}} inclusive. A permutation and its inverse have the same inversion number.

For example i n v ( ⟨ 1 , 2 , … , n ⟩ ) = 0 {\displaystyle {\mathtt {inv}}(\langle 1,2,\dots ,n\rangle )=0} since the sequence is ordered. Also, when n = 2 m {\displaystyle n=2m} is even, i n v ( ⟨ m + 1 , m + 2 , … , 2 m , 1 , 2 , … , m ⟩ ) = m 2 {\displaystyle {\mathtt {inv}}(\langle m+1,m+2,\dots ,2m,1,2,\dots ,m\rangle )=m^{2}} (because each pair ( 1 ≤ i ≤ m < j ≤ 2 m ) {\displaystyle (1\leq i\leq m<j\leq 2m)} 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,14 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.15 Standard comparison sorting algorithms can be adapted to compute the inversion number in time O(n log n).16

Inversion related vectors

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 ( v {\displaystyle v} ) like Wolfram.17 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 ( l {\displaystyle l} ) and right inversion count ( r {\displaystyle r} ). Interpreted as a factorial number the left inversion count gives the permutations reverse colexicographic,18 and the right inversion count gives the lexicographic index.

Inversion vector v {\displaystyle v} :With the element-based definition v ( i ) {\displaystyle v(i)} is the number of inversions whose smaller (right) component is i {\displaystyle i} .19

v ( i ) {\displaystyle v(i)} is the number of elements in π {\displaystyle \pi } greater than i {\displaystyle i} before i {\displaystyle i} . v ( i )     =     # { k ∣ k > i   ∧   π − 1 ( k ) < π − 1 ( i ) } {\displaystyle v(i)~~=~~\#\{k\mid k>i~\land ~\pi ^{-1}(k)<\pi ^{-1}(i)\}}

Left inversion count l {\displaystyle l} :With the place-based definition l ( i ) {\displaystyle l(i)} is the number of inversions whose bigger (right) component is i {\displaystyle i} .

l ( i ) {\displaystyle l(i)} is the number of elements in π {\displaystyle \pi } greater than π ( i ) {\displaystyle \pi (i)} before π ( i ) {\displaystyle \pi (i)} . l ( i )     =     # { k ∣ k < i   ∧   π ( k ) > π ( i ) } {\displaystyle l(i)~~=~~\#\left\{k\mid k<i~\land ~\pi (k)>\pi (i)\right\}}

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

r ( i ) {\displaystyle r(i)} is the number of elements in π {\displaystyle \pi } smaller than π ( i ) {\displaystyle \pi (i)} after π ( i ) {\displaystyle \pi (i)} . r ( i )     =     # { k ∣ k > i   ∧   π ( k ) < π ( i ) } {\displaystyle r(i)~~=~~\#\{k\mid k>i~\land ~\pi (k)<\pi (i)\}}

Both v {\displaystyle v} and r {\displaystyle r} 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. r ( i ) {\displaystyle r(i)} is the sum of inversions in row i {\displaystyle i} of the Rothe diagram, while v ( i ) {\displaystyle v(i)} is the sum of inversions in column i {\displaystyle i} . The permutation matrix of the inverse is the transpose, therefore v {\displaystyle v} of a permutation is r {\displaystyle r} of its inverse, and vice versa.

Example: All permutations of four elements

The following sortable table shows the 24 permutations of four elements (in the π {\displaystyle \pi } column) with their place-based inversion sets (in the p-b column), inversion related vectors (in the v {\displaystyle v} , l {\displaystyle l} , and r {\displaystyle r} 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 v {\displaystyle v} and l {\displaystyle l} always have the same digits, and that l {\displaystyle l} and r {\displaystyle r} are both related to the place-based inversion set. The nontrivial elements of l {\displaystyle l} are the sums of the descending diagonals of the shown triangle, and those of r {\displaystyle r} 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 π {\displaystyle \pi } , which is the same as colex order by l {\displaystyle l} . Lex order by π {\displaystyle \pi } is the same as lex order by r {\displaystyle r} .

3-element permutations for comparison
0
1
2
3
4
5
π {\displaystyle \pi } v {\displaystyle v} l {\displaystyle l} p-b r {\displaystyle r} #
01233210000000000000000000
12133121000010100101000011
21322310100101000010100101
33122131100111100112000022
42311322000022000021100112
53211232100122100122100123
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
π {\displaystyle \pi } v {\displaystyle v} l {\displaystyle l} p-b r {\displaystyle r} #
0123443210000000000000000000000000
1213443121000000100100100100000011
2132442310100001001000010010000101
3312442131100001101100110200000022
4231441322000000202000020110000112
5321441232100001202100120210000123
6124334210010010010000001001001001
7214334121010010110100101101001012
8142332410110011011000011020000202
9412332141110011111100111300000033
10241331422010010212000021120000213
11421331242110011212100121310000134
12134224310200002020000002011001102
13314224131200002120100102201001023
14143223410210012021000012021001203
15413223141210012121100112301001034
16341221432200002222000022220000224
17431221342210012222100122320000235
18234114323000000330000003111001113
19324114233100001330100103211001124
20243113423010010331000013121001214
21423113243110011331100113311001135
22342112433200002332000023221001225
23432112343210012332100123321001236

Weak order of permutations

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

Wikiversity has learning resources about Inversion (discrete mathematics)

Sequences in the OEIS:

  • Sequences related to factorial base representation
  • Factorial numbers: A007623 and A108731
  • Inversion numbers: A034968
  • Inversion sets of finite permutations interpreted as binary numbers: A211362   (related permutation: A211363)
  • Finite permutations that have only 0s and 1s in their inversion vectors: A059590   (their inversion sets: A211364)
  • Number of permutations of n elements with k inversions; Mahonian numbers: A008302   (their row maxima; Kendall-Mann numbers: A000140)
  • Number of connected labeled graphs with n edges and n nodes: A057500

Source bibliography

Further reading

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

Presortedness measures

References

  1. Aigner 2007, pp. 27. - Aigner, Martin (2007). "Word Representation". A course in enumeration. Berlin, New York: Springer. ISBN 978-3642072536.

  2. Comtet 1974, pp. 237. - 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. https://archive.org/details/Comtet_Louis_-_Advanced_Coatorics

  3. Knuth 1973, pp. 11. - Knuth, Donald (1973). "5.1.1 Inversions". The Art of Computer Programming. Addison-Wesley Pub. Co. ISBN 0201896850.

  4. Pemmaraju & Skiena 2003, pp. 69. - 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.

  5. Vitter & Flajolet 1990, pp. 459. - 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.

  6. Gratzer 2016, pp. 221. - Gratzer, George (2016). "7-2 Basic objects". Lattice theory. special topics and applications. Cham, Switzerland: Birkhäuser. ISBN 978-3319442358.

  7. Bóna 2012, pp. 57. - Bóna, Miklós (2012). "2.2 Inversions in Permutations of Multisets". Combinatorics of permutations. Boca Raton, FL: CRC Press. ISBN 978-1439850510.

  8. Bóna 2012, pp. 57. - Bóna, Miklós (2012). "2.2 Inversions in Permutations of Multisets". Combinatorics of permutations. Boca Raton, FL: CRC Press. ISBN 978-1439850510.

  9. Cormen et al. 2001, pp. 39. - 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.

  10. Barth & Mutzel 2004, pp. 183. - 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. https://doi.org/10.7155%2Fjgaa.00088

  11. Mannila 1985. - Mannila, Heikki (April 1985). "Measures of presortedness and optimal sorting algorithms". IEEE Transactions on Computers. C-34 (4): 318–325. doi:10.1109/tc.1985.5009382. https://doi.org/10.1109%2Ftc.1985.5009382

  12. Vitter & Flajolet 1990, pp. 459. - 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.

  13. Barth & Mutzel 2004, pp. 183. - 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. https://doi.org/10.7155%2Fjgaa.00088

  14. Gratzer 2016, pp. 221. - Gratzer, George (2016). "7-2 Basic objects". Lattice theory. special topics and applications. Cham, Switzerland: Birkhäuser. ISBN 978-3319442358.

  15. Mahmoud 2000, pp. 284. - 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.

  16. Kleinberg & Tardos 2005, pp. 225. - Kleinberg, Jon; Tardos, Éva (2005). Algorithm Design. ISBN 0-321-29535-8.

  17. Weisstein, Eric W. "Inversion Vector" From MathWorld--A Wolfram Web Resource http://mathworld.wolfram.com/InversionVector.html

  18. Reverse colex order of finitary permutations (sequence A055089 in the OEIS) //oeis.org/A055089

  19. Knuth 1973, pp. 11. - Knuth, Donald (1973). "5.1.1 Inversions". The Art of Computer Programming. Addison-Wesley Pub. Co. ISBN 0201896850.