Question: Please run the given buggy merge sort on array [5, 4, 9, 1] and demonstrate the merge process via a figure. Briefly state the bug

Please run the given buggy merge sort on array [5, 4, 9, 1] and demonstrate the merge process via a figure. Briefly state the bug and its fix

def merge(arr, p, q, r):

L = arr[p:q]

R = arr[q:r+1]

L.append(math.inf)

R.append(math.inf)

i, j = 0, 0

for k in range(p, r+1):

if L[i] <= R[j]:

arr[k] = L[i]

i += 1

else:

arr[k] = R[j]

j += 1

def mergeSort(arr, p, r):

if p < r:

q = (p+r) // 2

mergeSort(arr, p, q)

mergeSort(arr, q+1, r)

merge(arr, p, q, r)

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!