@@ -0,0 +1,1560 @@
+'''Copyright %5B2020%5D %5BAakash Deep%5D%0A%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0Ayou may not use this file except in compliance with the License.%0AYou may obtain a copy of the License at%0A%0A    http://www.apache.org/licenses/LICENSE-2.0%0A%0AUnless required by applicable law or agreed to in writing, software%0Adistributed under the License is distributed on an %22AS IS%22 BASIS,%0AWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0ASee the License for the specific language governing permissions and%0Alimitations under the License.'''%0A%0A%0A# Program to implement merge sort algorithm in Python3 language.%0Al=%5B4,5,9,8,7,6,2,3%5D%0A%0A''' Function which performs merge sort recursively by calling itself%0A again and again, dividing the list in half everytime it calls itself%0A until the base case arises which is when the length of list becomes 1.%0A And then merge the lists back together in sorted form'''%0A%0Adef merge_sort(l,s,e):%0A%09if s==e:%0A%09%09return %5Bl%5Bs%5D%5D%0A%09m=(e+s)//2%0A%09p1=merge_sort(l,s,m)%0A%09p2=merge_sort(l,m+1,e)%0A%09return merge(p1,p2)%0A%0A# %22merge%22 function performs the main action of merging together the elements of two list together in sorted order.%0A%0Adef merge(p1,p2):%0A%09i=0%0A%09j=0%0A%09sorted_list=%5B%5D%0A%0A%09while i %3C len(p1) and j %3C len(p2):%0A%09%09if p1%5Bi%5D%3C=p2%5Bj%5D:%0A%09%09%09sorted_list.append(p1%5Bi%5D)%0A%09%09%09i+=1%0A%09%09elif p1%5Bi%5D%3Ep2%5Bj%5D:%0A%09%09%09sorted_list.append(p2%5Bj%5D)%0A%09%09%09j+=1%0A%09while i %3C len(p1):%0A%09%09sorted_list.append(p1%5Bi%5D)%0A%09%09i+=1%0A%09while j %3C len(p2):%0A%09%09sorted_list.append(p2%5Bj%5D)%0A%09%09j+=1%0A%09return sorted_list%0A%0A# Calling the function merge_sort%0A%0Al=merge_sort(l,0,len(l)-1)%0Aprint(l)

Merge Sort (#153)