Content deleted Content added
→Inversion number: indicate bound on the number of inversion |
→See also: no longer exists |
||
(35 intermediate revisions by 14 users not shown) | |||
Line 1:
{{Short description|Pair of positions in a sequence where two elements are out of sorted order}}
[[File:Inversion qtl1.svg|thumb|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 [[total order|order]].
Line 6 ⟶ 9:
===Inversion===
Let <math>\pi</math> be a [[permutation]].
The [[#Example:_All_permutations_of_four_elements|inversion set]] is the set of all inversions. A permutation's inversion set using place-based notation is the same as the [[Permutation#Definition|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.{{sfn|Gratzer|2016|pp=221}}
The inversion is usually defined for permutations, but may also be defined for sequences:<br>Let <math>S</math> be a [[sequence]] (or [[multiset]] permutation{{sfn|Bóna|2012|pp=57}}). If <math>i < j</math> and <math>S(i) > S(j)</math>, either the pair of places <math>(i, j)</math>{{sfn|Bóna|2012|pp=57}}{{sfn|Cormen|Leiserson|Rivest|Stein|2001|pp=39}} or the pair of elements <math>\bigl(S(i), S(j)\bigr)</math>{{sfn|Barth|Mutzel|2004|pp=183}} is called an inversion of <math>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>\mathtt{inv}(X)</math>{{sfn|Mannila|
For example <math>\mathtt{inv}(\langle1,2,\dots, n\rangle)=0</math> since the sequence is ordered. Also <math>\mathtt{inv}(\langle n+1,n+2,\dots,2n,1,2,\dots, n\rangle)=n^2</math> as each pairs <math>(1\le i\le n < j\le 2n)</math> is an inversion. This last example shows that a sort that is intuitively sorted can still have a quadratic number of inversions.▼
▲For example <math>\mathtt{inv}(\langle1,2,\dots, n\rangle)=0</math> since the sequence is ordered. Also, when <math>n = 2m</math> is even, <math>\mathtt{inv}(\langle
It is the number of crossings in the arrow diagram of the permutation,{{sfn|Gratzer|2016|pp=221}} its [[Kendall tau distance]] from the identity permutation, and the sum of each of the inversion related vectors defined below.▼
▲
Other measures of
===Inversion related vectors===
Line 45 ⟶ 47:
:<math>r(i) ~~=~~ \# \{ k \mid k > i ~\land~ \pi(k) < \pi(i) \}</math>
Both <math>v</math> and <math>r</math> can be found with the help of a
==Example: All permutations of four elements==
[[File:2-element subsets of 4 elements; array, hexagonal.svg|thumb|The six possible inversions of a 4-element permutation]]
The following sortable table shows the 24 permutations of four elements (in the <math>\pi</math> column) with their place-based inversion sets (in the p-b column), inversion related vectors (in the <math>v</math>, <math>l</math>, and <math>r</math> columns), and inversion numbers (in the # column). (The
It can be seen that <math>v</math> and <math>l</math> always have the same digits, and that <math>l</math> and <math>r</math> are both related to the place-based inversion set. The nontrivial elements of <math>l</math> are the sums of the descending diagonals of the shown triangle, and those of <math>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.)
Line 69 ⟶ 71:
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 (order)|lattice]].
The [[Hasse diagram]] of the inversion sets ordered by the [[subset]] relation forms the [[skeleton (topology)|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.
Line 77 ⟶ 79:
== See also ==
{{wikiversity|Inversion (discrete mathematics)}}
* [[Factorial number system]]
* [[Permutation graph]]
* [[Damerau–Levenshtein distance]]
* [[Parity of a permutation]]
Line 119:
|url = https://archive.org/details/Comtet_Louis_-_Advanced_Coatorics
| chapter = 6.4 Inversions of a permutation of [n]
| publisher = D. Reidel Pub. Co | ___location = Dordrecht, Boston | year = 1974 | isbn = 9027704414 }}
* {{cite book
| first1=Thomas H. |last1=Cormen |authorlink1=Thomas H. Cormen
Line 141:
|title=Algorithm Design
|year=2005
|publisher=Pearson/Addison-Wesley
|isbn=0-321-29535-8 }}
* {{cite book
| last1 = Knuth | first1 = Donald
| title = [[The
| chapter = 5.1.1 Inversions
| publisher = Addison-Wesley Pub. Co | year = 1973 | isbn = 0201896850}}
Line 175 ⟶ 176:
=== Further reading ===
{{refbegin}}
* {{cite journal|journal=Journal of Integer Sequences|volume=4|year=2001|title=Permutations with Inversions|first=Barbara H.|last=Margolius|page=24|bibcode=2001JIntS...4...24M}}
{{refend}}
=== Presortedness measures ===
{{refbegin}}
*{{cite journal
| last = Mannila | first = Heikki | author-link = Heikki Mannila
| date = April 1985
| doi = 10.1109/tc.1985.5009382
| issue = 4
| journal = IEEE Transactions on Computers
| pages = 318–325
| title = Measures of presortedness and optimal sorting algorithms
| volume = C-34}}
* {{cite journal|first1=Vladimir|last1=Estivill-Castro|first2=Derick|last2=Wood|author2-link=Derick Wood|title=A new measure of presortedness|journal=Information and Computation|volume=83|issue=1|pages=111–119|year=1989|doi=10.1016/0890-5401(89)90050-3|doi-access=free}}
* {{cite journal|first=Steven S.|last=Skiena|year=1988|title=Encroaching lists as a measure of presortedness|journal=BIT|volume=28|issue=4|pages=755–784|doi=10.1007/bf01954897|s2cid=33967672}}
|