Consider the Sort-and-Count algorithm explained in section 5.3 of our text: "Counting Inversions"Suppose that the initial list is:92   71   36   91   27   48   14   34   81   26   24   65   78   51   37   22Sort-and-Count makes two recursive calls. The first recursive call inputs the first half of the initial list:92   71   36   91   27   48   14   34and returns the sorted version of the first half, as well as the number of inversions found in the first half (22). The second recursive call inputs the second half of the initial list:81   26   24   65   78   51   37   22and returns the sorted version of the second half, as well as the number of inversions found in the second half (19). Sort-and-Count then calls Merge-and-Count. To Merge-and-Count, Sort-and-Count passes the sorted versions of the two halves of the original list:14   27   34   36   48   71   91   92, and22   24   26   37   51   65   78   81Merge-and-Count begins merging the two half-lists together, while counting inversions.14   27   34   36   48   71   91   92      22   24   26   37   51   65   78   81 14   22   24   26   27   34   36   37   48   51   65   71   78   81   91   92      7    7    7                   4         3    3         2    2     (inversions)The inversions counted during the merge are shown in the last line above. The total number of inversions counted between the two sorted halves is7+7+7+4+3+3+2+2 = 35.Therefore the total number of inversions in the original list is 22+19+35 = 76.YOUR ASSIGMENT:Do the same work as above, except starting with this initial list:26   81   87   32   66   72   86   97   23   48   14   71   89   18   49   62

Question
Asked Apr 4, 2019
8 views

Consider the Sort-and-Count algorithm explained in section 5.3 of our text: "Counting Inversions"

Suppose that the initial list is:

92   71   36   91   27   48   14   34   81   26   24   65   78   51   37   22

Sort-and-Count makes two recursive calls. The first recursive call inputs the first half of the initial list:

92   71   36   91   27   48   14   34

and returns the sorted version of the first half, as well as the number of inversions found in the first half (22). The second recursive call inputs the second half of the initial list:

81   26   24   65   78   51   37   22

and returns the sorted version of the second half, as well as the number of inversions found in the second half (19). Sort-and-Count then calls Merge-and-Count. To Merge-and-Count, Sort-and-Count passes the sorted versions of the two halves of the original list:

14   27   34   36   48   71   91   92, and

22   24   26   37   51   65   78   81

Merge-and-Count begins merging the two half-lists together, while counting inversions.

14   27   34   36   48   71   91   92      22   24   26   37   51   65   78   81

 

14   22   24   26   27   34   36   37   48   51   65   71   78   81   91   92

      7    7    7                   4         3    3         2    2     (inversions)

The inversions counted during the merge are shown in the last line above. The total number of inversions counted between the two sorted halves is

7+7+7+4+3+3+2+2 = 35.

Therefore the total number of inversions in the original list is 

22+19+35 = 76.

YOUR ASSIGMENT:

Do the same work as above, except starting with this initial list:

26   81   87   32   66   72   86   97   23   48   14   71   89   18   49   62

check_circle

Expert Answer

Step 1

Given:

Initial list:

26   81   87   32   66   72   86   97   23   48   14   71   89   18   49   62

Algorithm:

  • First, divide the list into two halves.
  • Sort and count the two halves.
  • Merge and count the two halves.
  • Then total the all inversion count.
Step 2

Step 1:

fullscreen
Step 3

Step 2:

Counting inversions for the first h...

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Algorithms

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Create a new file in C++ and save it as lab12_XYZ.cpp  Consider rolling two six-sided dice. Whil...

A: Program Instructions:Declare the header files, constants, and prototypes.In main() call functions di...

question_answer

Q: Create a trigger called Trig_Enroll_BI on the ENROLLMENT table that fires before an INSERT statement...

A: Solution:Create the trigger with name of “Trig_Enroll_BI” for ENROLLMENT table.The followings algori...

question_answer

Q: You are not required to execute the queries. However, your syntax must by accurate.You must give at ...

A: Hey, since there are multiple sub-part questions posted, we will answer first three questions. If yo...

question_answer

Q: Create a Crow's Foot ERD to include the following business rules for the ProdCo company:a. Each sa...

A: We will draw the diagram one part by part. So first we willd ra diagram for very first two points.a)...

question_answer

Q: Assume that an array of integers named a that contains exactly five elements has been declared and i...

A: Didn’t mention which language to do the problem. So, did the problem in Java.Given:Let assume an arr...

question_answer

Q: Design a program that prompts user enters user name and password. Until user entered user name as "F...

A: Note: The given program is compiled and executed in "NetBeans IDE"

question_answer

Q: I am trying to write a program to convert a number from an integer to an octal. How do I do this wit...

A: As there is no particular programming language mentioned, we are doing this conversion of integer nu...

question_answer

Q: On its own, the number 190 is an example of:

A: On its own, the number 190 is a decimal number.

question_answer

Q: 11,12,13

A: Two main advantages of storing data digitally rather than in analog format are:Data stored in digita...