You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In traditional Merge Sort, the array is recursively divided into halves until we reach subarrays of size 1. In 3-way Merge Sort, the array is recursively divided into three parts, reducing the depth of recursion and potentially improving efficiency.
3
-
'''
3
+
"""
4
+
5
+
4
6
defmerge(arr, left, mid1, mid2, right):
5
-
6
7
# Sizes of three subarrays
7
8
size1=mid1-left+1
8
9
size2=mid2-mid1
9
10
size3=right-mid2
10
-
11
+
11
12
# Temporary arrays for three parts
12
-
left_arr=arr[left:left+size1]
13
-
mid_arr=arr[mid1+1:mid1+1+size2]
14
-
right_arr=arr[mid2+1:mid2+1+size3]
15
-
13
+
left_arr=arr[left : left+size1]
14
+
mid_arr=arr[mid1+1 : mid1+1+size2]
15
+
right_arr=arr[mid2+1 : mid2+1+size3]
16
+
16
17
# Merge three sorted subarrays
17
18
i=j=k=0
18
19
index=left
19
-
20
+
20
21
whilei<size1orj<size2ork<size3:
21
-
min_value=float('inf')
22
+
min_value=float("inf")
22
23
min_idx=-1
23
-
24
+
24
25
# Find the smallest among the three current elements
0 commit comments