Question: CODE FOR merge() def merge(left,right): result=[] i,j=0,0 while i CODE FOR mergeSort() def mergeSort(data): # Sort myself using a merge sort. if len(data) return data

 CODE FOR merge() def merge(left,right): result=[] i,j=0,0 while i CODE FOR

CODE FOR merge()

def merge(left,right): result=[] i,j=0,0 while i

CODE FOR mergeSort()

def mergeSort(data): # Sort myself using a merge sort.

if len(data)

return data

middle = len(data)//2

left=mergeSort(data[:middle]

right=mergeSort(data[middle:]

return merge(left,right)

Your task in this lab is to modify the mergeSort program given in the lecture notes such that it returns the number of inversions and the sorted list. In order to complete this task you will have to make changes to the mergeSort function and the merge function. Here is how merge sort will be called by the main function: def main(): alist - [10,9,8,7,6,5,4,3,2,1] inversion_count, sorted_list - mergeSort (alist) print('Inversion Count -',inversion_count) print( Sorted List', sorted_list) main() Here are some sample outputs for various values of alist Input alist - [10,9,8,7,6,5,4,3,2,1]Inversion Count45 alist1,2,3,4,51 alist -[1,2,10,4,5,8,7] alist -L Sample Output Sorted List- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Inversion Count0 Sorted List[1, 2, 3, 4, 5 Inversion Count5 Sorted List = [1, 2, 4, 5, 7, 8, 10] Inversion Count 0 Sorted List- NOTE: You may assume the list is always made of valid integer values only

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!