Question: Question: Implement an algorithm that counts the inversions of your linked list structure (see section 1.2). For full points the algorithm should have linearithmic worst-case

Question: Implement an algorithm that counts the inversions of your linked list structure (see section 1.2). For full points the algorithm should have linearithmic worst-case time complexity (else 10P reduction). Extend your BubbleSort implementation to count the number of calls to Swap and compare with the result of your inversion count. Make sure the result matches with the information from section 1.2.
Please explain your code in detail :-)
Algorithm 1 BubbleSort Require: a is a list data structure of length n>0. swapped true while R 20 and 8Wapped = true do swapped false for i 0 to R do if ali]> ali+1] then true SWAP(a, i, i +1) end if end for RR-1 end while Ensure: a is an ordered permutation of a. Stable Sorting Let a be a list data structure of length n>0.Furthermore let S be a sorting algorithm and a be the ordered permutation of a after applying S according to the total order relation with associated equality relation = We call S 8table if and only if for all z, y with ali]s z=y-aj] and i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
