(Latest Revision:
Mar 18, 2021)
Sort and Count Problem
EXAMPLE:
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:95 36 41 86 43 44 67 47 60 50 42 52 66 34 75 48
Directions For Submitting Solution:
Here below is a sample of the information I want in your e-mail. This shows what the information would be for the example problem above. You must give me the same kind of information for your assigned problem.
Sorted Left Half: 14 27 34 36 48 71 91 92 (22 inversions found here)
Sorted Right Half: 22 24 26 37 51 65 78 81 (19 inversions found here)
Merge and Count Results:
Sorted Left Half-List Sorted Right Half-List
14 27 34 36 48 71 91 92 22 24 26 37 51 65 78 81
Merged Full List
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 counted)
Total Inversions Found in Final Merge: 7+7+7+4+3+3+2+2 = 35
Grand Total of Inversions in List: 22+19+35 = 76
COPY AND PASTE the text of your solution into the e-mail.
DO NOT ATTACH A FILE.
COPY AND PASTE the text into the message window of the e-mail.
Send the e-mail to
tester2@cs.csustan.edu
with this subject line:
CS 4440 Sort+Count Problem
(Copy & Paste that exact subject line. Get it right, or get no credit.)