Python: Sort unsorted numbers using Merge-insertion sort
Write a Python program to sort unsorted numbers using Merge-insertion sort.
From Wikipedia,
In computer science, merge-insertion sort or the Ford–Johnson algorithm is a comparison sorting algorithm published in 1959 by L. R. Ford Jr. and Selmer M. Johnson.It uses fewer comparisons in the worst case than the best previously known algorithms, binary insertion sort and merge sort, and for 20 years it was the sorting algorithm with the fewest known comparisons. Although not of practical significance, it remains of theoretical interest in connection with the problem of sorting with a minimum number of comparisons. The same algorithm may have also been independently discovered by Stanisław Trybuła and Czen Ping.
Sample Solution:
Python Code:
Sample Output:
Original list: [4, 3, 5, 1, 2] After applying Merge-insertion Sort the said list becomes: [1, 2, 3, 4, 5] [4, 3, 5, 1, 2] Original list: [5, 9, 10, 3, -4, 5, 178, 92, 46, -18, 0, 7] After applying Merge-insertion Sort the said list becomes: [-18, -4, 0, 3, 5, 5, 7, 9, 10, 46, 92, 178] [5, 9, 10, 3, -4, 5, 178, 92, 46, -18, 0, 7] Original list: [1.1, 1, 0, -1, -1.1, 0.1] After applying Merge-insertion Sort the said list becomes: [-1.1, -1, 0, 0.1, 1, 1.1] Original list: ['z', 'a', 'y', 'b', 'x', 'c'] After applying Merge-insertion Sort the said list becomes: ['a', 'b', 'c', 'x', 'y', 'z']
Flowchart:



Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to sort unsorted strings using natural sort.
Next: Python Recursion Exercise Home.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics