Algorithm
Merge Sort in Python
- LinkList
Merge is another sorting Technique, the merge sort is divide and conquer algorithm,The merge sort is break the list into the sublist,this algorithm complexity is Ο(n log n), that means this respected algorithm,Merge sort is divide the array into equal halves and combining the sorted manner,
def MergeSort(arr):
if len(arr)>1:
mid=(len(arr))//2;
l=arr[:mid];
r=arr[mid:];
MergeSort(l);
MergeSort(r);
i=j=k=0;
while i<len(l) and j<len(r):
if l[i] < r[j]:
arr[k]=l[i];
i+=1;
else:
arr[k]=r[j];
j+=1;
k+=1;
while i<len(l):
arr[k]=l[i];
i+=1;
k+=1;
while j<len(r):
arr[k]=r[j];
j+=1;
k+=1;
arr=[43,56,78,9,5,3,7,0];
obj=MergeSort(arr)
for i in range(len(arr)):
print(arr);
if i==0:
break;