Question: 2. (25 Points) Let A[0..n - 1] be an array of real numbers (or any ordered set). A pair (A[i], A[j]) is said to

2. (25 Points) Let A[0..n - 1] be an array of real 

2. (25 Points) Let A[0..n - 1] be an array of real numbers (or any ordered set). A pair (A[i], A[j]) is said to be an inversion if these numbers (elements) are out of order, i.e., i < j but A[i] > A[j]. Note that this pair need not be adjacent. The array/sequence (3, 2, 1) contains three inversions: (3,2), (2,1), and (3,1). (10 Points) Write a program with a nave O(n) [sorting] algorithm that counts the number of inversions in such an array A. Call your program/project 'easyinversioncount'. (15 Points) Write a program with a O(n log n) [sorting] algorithm that counts the number of inversions in such an array A. Call your program/project 'fastinversioncount'. (Hints to follow...)

Step by Step Solution

3.36 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here are the solutions for the two programs to count the number of inversions in an ar... 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

Students Have Also Explored These Related Programming Questions!