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