Question: Let A = A[1], , A[n] be an array of n distinct positive integers (the value of these integers could be very large). An inversion

 Let A = A[1], , A[n] be an array of n

Let A = A[1], , A[n] be an array of n distinct positive integers (the value of these integers could be very large). An inversion is a pair of indices i and j such that i A [j]. For example in the array [30000, 80000, 20000, 40000, 10000], the pair i = 1 and j = 3 is an inversion because A[1] = 30000 is greater than A[3] = 20000. On the other hand, the pair i = 1 and j = 2 is not an inversion because A[1] = 30000 is smaller than A [2] = 80000. In this array there are 7 inversions and 3 non-inversions. (a) Describe in one sentence the natural brute-force algorithm. (b) What is the complexity of the natural brute-force algorithm? (No explanation.) (c) Now give an O(n log n)-time algorithm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!