diff --git a/algorithms/Python/README.md b/algorithms/Python/README.md index f9c50fa4..d715cdf0 100644 --- a/algorithms/Python/README.md +++ b/algorithms/Python/README.md @@ -38,6 +38,7 @@ 6. [Heap Sort](sorting/heap-sort.py) 7. [Radix Sort](sorting/radix-sort.py) 8. [Shell Sort](sorting/shell-sort.py) +9. [Merge sort](sorting/merge_sort.py) ## Strings diff --git a/algorithms/Python/sorting/merge_sort.py b/algorithms/Python/sorting/merge_sort.py new file mode 100644 index 00000000..cb885ca3 --- /dev/null +++ b/algorithms/Python/sorting/merge_sort.py @@ -0,0 +1,34 @@ +## Implementation of merge sort +## Merge Sort is a recursive algorithm which sorts the list by divide and conquer approach +def merge_sort(list): + # if list size <= 1, the list is anyway sorted! :) + if len(list)==1: return list + #splitting the list into half + mid = len(list)//2 # integer division + l = list[:mid] + r = list[mid:] + merge_sort(l) # recursive calling of left part of list + merge_sort(r) # recursive calling of right part of list + #merging the left and right parts + i=j=k=0 + while(i