diff --git a/Sorting/Merge_Sort.py b/Sorting/Merge_Sort.py new file mode 100644 index 0000000..4e3207e --- /dev/null +++ b/Sorting/Merge_Sort.py @@ -0,0 +1,61 @@ +#Merge Sort - a way of sorting, which uses divide and conquer method. + +def merge_sort(values): + + # Splitting of list into approximately two equal halves + if len(values)>1: + m = len(values)//2 + + # Splitting left and right sublists + left = values[:m] + right = values[m:] + + # Recrusive call to merge_sort to do the same process for the available sublist + left = merge_sort(left) + right = merge_sort(right) + + values =[] + + # Comparing the first elements of both sublists and appending the lowest of two to "values" list + # list.pop(0) => removes the first element (0th index) of list + while len(left)>0 and len(right)>0: + + # condition that, left sublist element is lesser than that of right + if left[0]