Question: Let A[1 n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is

Let A[1 ¬ n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A.
a. List the five inversions of the array ¬2, 3, 8, 6, 1¬.
b. What array with elements from the set {1, 2, . . . , n} has the most inversions? How many does it have?
c. What is the relationship between the running time of insertion sort and the number of inversions in the input array? Justify your answer.
d. Give an algorithm that determines the number of inversions in any permutation on n elements in Θ (n lg n) worst-case time. (Hint: Modify merge sort.)

Step by Step Solution

3.44 Rating (167 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a The inversions are 1 5 2 5 3 4 3 5 4 5 Remember that inversions are specified by indices rather than by the values in the array b The array with ele... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (1 attachment)

Word file Icon

C-S-A (80).docx

120 KBs Word File

Students Have Also Explored These Related Algorithms Questions!