2
$\begingroup$

the way I understood inversions is the number of operations ( exchanging positions of two numbers keeping other numbers at same place) to be done to reach a given permutation. To calculate odd or even permutation, I count the number of inversions using a method Which I learnt online mentioned below.

Eg: ${1\ 4\ 3\ 2}$ takes $3$ inversions, because $4$ > $3,2$ and $3$ > $2$ so $2+1$ = $3$ inversions.

But if I keep $1,3$ at same place and exchange $2,4$ i obtain the given permutation. thus it is odd permutation. but the method I learnt online gives different value.

Is this method ( a popular one ) used to determine only odd/even permutation, or actually count the number of inversions?? Is there any method to calculate number of inversions, just by inspection?

  • 0
    The method you learnt online tells you the permutation is odd, and you also think it is odd, so what is the question?2017-02-22
  • 0
    The method you learned does not tell you what the minimum number of inversions is to get a given permutation. It tells you whether the permutation is odd or even. In your case, you noted that the permutation is actually just the single inversion (2,4), it is thus odd (since it consists of 1 inversion) Your method gave you a decomposition of the permutation into 3 inversions. Since 3 is also odd you conclude again that the permutation is odd, same as what you concluded before. There is no contradiction.2017-02-22
  • 0
    Don't mix up inversions and transposition. The described method gives you *the* number of *inversions*, which is unambiguously defined. This is not the minimum number of *transpositions* to convert the permutation into identity. The example permutation is a transposition with 3 inversions.2017-02-22
  • 0
    it doesnt give me minimum number of inversions.2017-02-22

2 Answers 2

3

I don't know any smarter way to count inversions in a permutation than simply looking at all pairs of elements to see whether they are inverted or not. In principle, I suppose, there could be. But that doesn't matter, because it would be very unusual to have a good reason to want to know that number for a particular permutation. (The sole exception I can think of is solving homework exercises that check whether you have understood the definition).

Counting inversions is mainly good for theoretical purposes: It's a way to argue that whether a permutation is odd or even is well-defined -- that is, that there is no permutation that can be made both as a product of an odd number of transpositions and an even number of transpositions.

It's not a particularly slick method for finding the parity of a permutation, because there are $\frac{n^2-n}2$ possible inversions to check for an $n$-element permutation, and that number grows uncomfortably fast when $n$ is large.

It is much quicker to find the parity of a permutation by writing it out in disjoint cycle form, and then counting how many cycles of even length there are (an even length cycle is an odd permutation, and vice versa). This can be done in time linear in $n$.

Another quick method (but not quite as suited for pencil-and-paper implementations) is to actually create a sequence of transpositions that reverses the permutation you're looking at, by moving one element at a time into its proper place, exchanging it with what is already there. If you maintain a lookup table of where to find which number along the way, this can be done in linear time too. (Just remember that exchanging an element with itself is not a transposition).

  • 0
    the method mentioned in the third para gives minimum number of inversions?2017-02-22
  • 0
    @jnyan: As others have explained, "minimum number of inversions" does not make sense. A permutation has an exact, definite number of inversions, neither more nor less. The way to find this number is indeed to check all pairs of positions and see whether they are inverted or not. My point is that in most cases I can think of you _don't actually want to know the number of inversions_, because the only thing this number is useful for is for defining whether the permutation is odd or even, and there are easier way to discover _that_.2017-02-22
  • 0
    thank you very much. I get it about the inversions part. Now imagine I have an initial order of things and I use my two hands to get a particular desired arrangement. meaning i can exchange positions of only two things. So if I know the final arrangement, and given an initial arrangement, Is there a way for me to know the number of times I have to exchange things? without actually doing it, or without trial and error.2017-02-22
  • 1
    @jnyan: Write out the permutation as disjoint cycles, and spend $(k-1)$ transpositions on each $k$-cycle.2017-02-22
0

The parity is only odd/even. The number of transpositions to reach a permutation may vary, but only so in a even number of steps (resulting in the parity being invariant).

One way to count it is by observing that a permutation is a combination of disjoint cycles. Then you use the fact that the parity of a cycle is odd if it has even length and vice versa. In your case you have three cycles: $(1)$, $(2,4)$ and $(3)$, two even and one odd which makes the parity odd.

  • 0
    The number of *transpositions* to reach a permutation may vary. The number of *inversions* is a well-defined property of the permutation.2017-02-22
  • 0
    @ReinhardMeier Yes, I changed that as you wrote that comment...2017-02-22