For a word over a totally ordered alphabet, an inversion of a word is a pair of positions with . Equal symbols contribute no inversion of a word. In
baba, with , the pairs are , so the word inversion number is three. Counting these pairs records distance from sorted order even when letters repeat; replacing the letters by distinct ordered labels gives the inversion of a permutation case. New to topics? Read the docs here!