CMIMC 2017 Computer Science Problem 5

Given a list A of n real numbers, the following algorithm, known as insertion sort, sorts the elements of A from least to greatest.

1: \textbf{FUNCTION } IS(A)
2: \quad \textbf{FOR } i=0, \ldots, n-1 :
3: \quad \quad j \leftarrow i
4: \quad \quad \quad \textbf{WHILE } j>0 \& A[j-1]>A[j] :
5: \quad \quad \quad \quad \textbf{SWAP } A[j], A[j-1]
6: \quad \quad \quad \quad j \leftarrow j-1
7: \textbf{RETURN } A

As A ranges over all permutations of \{1,2, \ldots, n\}, let f(n) denote the expected number of comparisons (i.e., checking which of two elements is greater) that need to be made when sorting A with insertion sort. Evaluate f(13)-f(12).