You are not right. The number of transpositions will not always be 3
but will vary.
Your first example (1,2,3,4)
needs no transpositions (it is the original order) so it is an even permutation. Your second example (1,2,4,3)
can be done with one transposition (swap the 3
and the 4
) so it is odd. Your third example (1,3,2,4)
can also be done with one transposition (swap the 2
and the 3
) so it is odd. And so on.
An example you did not give is (1,3,4,2)
, which can be done with two transpositions (swap the 2
and the 3
, then swap the 2
and the 4
) so this is an even transposition. Another final example is (2,3,4,1)
which can be done with three transpositions (swap the 1
and 2
, then swap 1
and 3
, then swap 1
and 4
) so this is odd.
No permutation of four elements will require more than three transpositions, but many can be done in fewer. Note that when I say "can be done with one transposition" the permutation can be done with a different number of transpositions, such as with three or five. However, a mathematical theorem states that if a permutation can be done with n transpositions and also with k transpositions, then n and k have the same parity--they are both even or both odd. So an "even permutation" can be done with an even number of transpositions, but we neither know nor care what the exact number is. An "odd permutation" can be done with an odd number of transpositions--one or three or five or ....
Ask if you need help in writing code that determines the parity of a permutation.