Search for question
Question

Let A[1 .. n] be an array of n distinct numbers. If iA[j], then the pair (i, j) is called an inversion

of A.

6a) List the five inversions of the array <2, 3, 8, 6, 1>.

6b) What array with elements from the set {1, 2,..., n} has the most inversions? How many does it have?

6c) What is the relationship between the running time of insertion sort and the number of inversions in the input

array? Justify your answer.

6d) Give an algorithm that determines the number of inversions in any permutation on n elements in O(n lg n)

worst-case time. (Hint: Modify merge sort.)

Fig: 1