Featured
- Get link
- X
- Other Apps
Merge sort in python
Merge sort use divide and conquer method. In this it will divide the process or list into small subprocess or sublist then calculate and merge the subprocess/sublist into singe process/list
The entire list will be separated into sublist untill the sublist consist of one element. Merge sort is recursive algorithm after dividing into sublist it then merge the sublist item in sorted order. Two sorted list are formed into single sorted list
Algorithm:
1) if no of item>=1 exit else
2) Divide the list into two list, firstlist and secondlist until contain one element
3) Sort first and second list
4) merge the sorted list to get sorted list
Best time complexity: 0[nlogn]
Average time complexity: 0[nlogn]
Worst time complexity: 0[nlogn]
Working process:
Take list [61, 3, 43, 25, 16, 34]
by seeing the above diagram hope you understand the working process. Initially the list is separated into sublist until it contains one element after separated the list is merged based on the sorting order of the element.
Code for Merge sort:
Output :
Hope you understand the program and try yourself for more clear view ,feel free to comment your thoughts!!
- Get link
- X
- Other Apps

Comments
Post a Comment