In computer science and discrete mathematics a sequence has an inversion where two of its elements are out of their natural order.
Let π{\displaystyle \pi } be a permutation. If i<j{\displaystyle i<j} and π(i)>π(j){\displaystyle \pi (i)>\pi (j)}, either the pair of places (i,j){\displaystyle (i,j)} or the pair of elements (π(i),π(j)){\displaystyle {\bigl (}\pi (i),\pi (j){\bigr )}} is called an inversion of π{\displaystyle \pi }.