Inversion (discrete mathematics)

From HandWiki
Short description: Pair of positions in a sequence where two elements are out of sorted order
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.

Definitions

Inversion

Let [math]\displaystyle{ \pi }[/math] be a permutation. There is an inversion of [math]\displaystyle{ \pi }[/math] between [math]\displaystyle{ i }[/math] and [math]\displaystyle{ j }[/math] if [math]\displaystyle{ i \lt j }[/math] and [math]\displaystyle{ \pi(i) \gt \pi(j) }[/math]. The inversion is indicated by an ordered pair containing either the places [math]\displaystyle{ (i, j) }[/math][1][2] or the elements [math]\displaystyle{ \bigl(\pi(i), \pi(j)\bigr) }[/math].[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 [math]\displaystyle{ S }[/math] be a sequence (or multiset permutation[7]). If [math]\displaystyle{ i \lt j }[/math] and [math]\displaystyle{ S(i) \gt S(j) }[/math], either the pair of places [math]\displaystyle{ (i, j) }[/math][7][8] or the pair of elements [math]\displaystyle{ \bigl(S(i), S(j)\bigr) }[/math][9] is called an inversion of [math]\displaystyle{ S }[/math].

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 [math]\displaystyle{ \mathtt{inv}(X) }[/math][10] of a sequence [math]\displaystyle{ X=\langle x_1,\dots,x_n\rangle }[/math], 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 [math]\displaystyle{ \frac{n(n-1)}2 }[/math] inclusive. A permutation and its inverse have the same inversion number.

For example [math]\displaystyle{ \mathtt{inv}(\langle1,2,\dots, n\rangle)=0 }[/math] since the sequence is ordered. Also, when [math]\displaystyle{ n = 2m }[/math] is even, [math]\displaystyle{ \mathtt{inv}(\langle m+1,m+2,\dots,2m,1,2,\dots, m\rangle)=m^2 }[/math] (because each pair [math]\displaystyle{ (1\le i\le m \lt j\le 2m) }[/math] 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]

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 ([math]\displaystyle{ v }[/math]) 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 ([math]\displaystyle{ l }[/math]) and right inversion count ([math]\displaystyle{ r }[/math]). 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 vector [math]\displaystyle{ v }[/math]:
With the element-based definition [math]\displaystyle{ v(i) }[/math] is the number of inversions whose smaller (right) component is [math]\displaystyle{ i }[/math].[3]

[math]\displaystyle{ v(i) }[/math] is the number of elements in [math]\displaystyle{ \pi }[/math] greater than [math]\displaystyle{ i }[/math] before [math]\displaystyle{ i }[/math].
[math]\displaystyle{ v(i) ~~=~~ \# \{ k \mid k \gt i ~\land~ \pi^{-1}(k) \lt \pi^{-1}(i) \} }[/math]

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

[math]\displaystyle{ l(i) }[/math] is the number of elements in [math]\displaystyle{ \pi }[/math] greater than [math]\displaystyle{ \pi(i) }[/math] before [math]\displaystyle{ \pi(i) }[/math].
[math]\displaystyle{ l(i) ~~=~~ \# \left\{ k \mid k \lt i ~\land~ \pi(k) \gt \pi(i) \right\} }[/math]

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

[math]\displaystyle{ r(i) }[/math] is the number of elements in [math]\displaystyle{ \pi }[/math] smaller than [math]\displaystyle{ \pi(i) }[/math] after [math]\displaystyle{ \pi(i) }[/math].
[math]\displaystyle{ r(i) ~~=~~ \# \{ k \mid k \gt i ~\land~ \pi(k) \lt \pi(i) \} }[/math]

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

Example: All permutations of four elements

The six possible inversions of a 4-element permutation

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


Weak order of permutations

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:

References

  1. Aigner 2007, pp. 27.
  2. Comtet 1974, pp. 237.
  3. 3.0 3.1 Knuth 1973, pp. 11.
  4. Pemmaraju & Skiena 2003, pp. 69.
  5. 5.0 5.1 Vitter & Flajolet 1990, pp. 459.
  6. 6.0 6.1 Gratzer 2016, pp. 221.
  7. 7.0 7.1 Bóna 2012, pp. 57.
  8. Cormen et al. 2001, pp. 39.
  9. 9.0 9.1 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

Further reading

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

Presortedness measures

  • "Measures of presortedness and optimal sorting algorithms". IEEE Transactions on Computers C-34 (4): 318–325. April 1985. doi:10.1109/tc.1985.5009382. 
  • Estivill-Castro, Vladimir; Wood, Derick (1989). "A new measure of presortedness". Information and Computation 83 (1): 111–119. doi:10.1016/0890-5401(89)90050-3. 
  • Skiena, Steven S. (1988). "Encroaching lists as a measure of presortedness". BIT 28 (4): 755–784. doi:10.1007/bf01954897.