Swaps and Inversions I explained in class why every permutation can be obtained as a product [composition] of swaps and that there are multiple ways to do this. In class, I also mentioned, without explaining why it is true, fact ( ) below: If there is a way to express a permutation p as the product of an (respectively number of swaps, then every way of expressing p as the product of swaps will contain an (respectively number of swaps. In other ( ) words, if p has been expressed as a product of swaps in two different ways, it is not possible for one of the products to contain an even number of swaps and the other product to contain an odd number of swaps. This handout will explain why this statement is true. explanation is that of an inversion in a permutation: The key idea in the Definition. Let permutation p be written in word form. An inversion in p is a pair of letters that are out of order in p. For example, consider the permutation CDGEFBA in P 7. For each letter, we will count the number of inversions that start with that letter; the total of these counts the total number of inversions. Letter: A B C D E F G Total number of inversions: # of inversions with that letter on the left:
Thus, the permutation CDGEFBA has thirteen inversions. At this point, please do the first classwork assignment. The connection between inversions and swaps is this: If permutation p contains an (respectively number of inver- ( ) odd sions, and if (a, b) is any swap, then (a, b) p will contain an (respectively even) number of inversions. For example, let us compose the swap (3, 6) with the permutation p = CDGEFBA from the previous page: the product is CDBEFGA. Let us count the total number of inversions in this new word. Letter: A B C D E F G Total number of inversions: # of inversions with that letter on the left: At this point, please do the second classwork assignment. The reason ( ) is true is that, as I will show: Composing (a, b) with p will always add or subtract an ODD number ( ) of inversions.
a b p Block I l 1 Block II l 2 Block III (a, b) p Block I l 2 Block II l 1 Block III Table 1: Composing (a, b) with p. I will explain why ( ) is true in two steps. First, let me set the stage. Say that, in p, letter l 1 is in position a and letter l 2 is in position b. 1 Then we can represent p and (a, b) p as shown in Table 1 (where Block I is the stuff to the left of l 1, Block II is the stuff between l 1 and l 2, and Block III is the stuff to the right of l 2 ). 2 Proof of ( ), Step 1. In the table below, let us localize the changes to the number of inversions block-by-block; I will work a specific example at the board to help explain how to determine the correct entries. As you will see, the changes can be localized very precisely. in Block I Change to Number of Inversions, Tracked Block-by-Block Right Right Right Right letter of letter of letter of letter of letter of inversion inversion inversion inversion inversion is in is is in is is in Block I l 1 Block II l 2 Block III of inversion is l 1 in Block II of inversion is l 2 in Block III 1 Assume a < b; that is, let a represent the smaller of these two numbers. 2 Depending upon the values of a and b, note, one or even two of the blocks might be empty.
Proof of ( ), Step 2. At this point, except for the ±1, we have localized all of the changes to the two boxes that received question marks. I will finish the proof of statement ( ) by showing that the sum of the numbers in these two boxes must be even, so that the total number of changes (including the ±1) must be odd. I will show this in the case that l 1 comes before l 2 in the alphabet; the argument for the other case is identical in structure. I will need to use some algebra: Let x denote the number of letters in Block II that come before l 1 in the alphabet; let y denote the number of letters in Block II that come between l 1 and l 2 in the alphabet; and let z denote the number of letters in Block II that come after l 2 in the alphabet. In other words, if you were to take l 1, l 2, and the Block II letters and put them all into into alphabetical order, you would see l 1 l 2 Let us now find, in terms of x, y and z, the change in the number of [l 1 Block II] inversions, as well as the change to the number of [l 2 Block II] inversions, as we move from p to (a, b) p. I will again work a specific example at the board to help you keep track of the computation. Below, I have modified the relevant piece of Table 1 by alphabetizing Block II. a Part of p l 1 {{ b l 2 Part of (a, b) p l 2 {{ l 1
Number of Number of Column 2 minus Inversions in p Inversions in (a, b) p Column 1 l 1 Block II l 2 Block II Column Sum The number 2y in the bottom right position is the same number you would get by adding the two question-mark numbers; and obviously the number 2y is even for any number y. The proof is complete [for the case: l 1 comes before l 2 in the alphabet]. Extra Credit Problem. Supply the proof for the case: l 2 comes before l 1 in the alphabet. Always Even or Always Odd It is now easy to see why statement ( ) at the beginning of the handout must be true. Say you compute a product of swaps. You start with the identity permutation, which has an even number of inversions, 3 and apply your swaps one-by-one. Each swap reverses the evenness/oddness of the product, so at the end, the number of inversions in your permutation will be even (respectively if the number of swaps you multiply together is even (respectively. Now say you and someone else independently compute the same permutation by multiplying swaps. If this permutation has an odd number of inversions, both you and she must have used an odd number of swaps; and if this permutation has an even number of inversions, both you and she must have used an even number of swaps. 3 The identity (in which all the letters are in alphabetical order) has zero inversions, and zero is an even number.