- A stable sorting algorithm works in O(n Log n) time
- Used in Java’s Arrays.sort() as well as Python’s sorted() and sort().
- First sort small pieces using Insertion Sort, then merges the pieces using merge of merge sort.
We divides the Array into blocks known as Run. We sort those runs using insertion sort one by one and then merge those runs using combine function used in merge sort. If size of Array is less than run, then Array get sorted just by using Insertion Sort. The size of run may vary from 32 to 64 depending upon size of array. Note that merge function performs well when sizes subarrays are powers of 2. The idea is based on the fact that insertion sort performs well for small arrays.
Details of below implementation :
- We consider size of run as 32.
- We one by one sort pieces of size equal to run
- After sorting individual pieces, we merge them one by one. We double the size of merged subarrays after every iteration.
Given Array is 5 21 7 23 19 After Sorting Array is 5 7 19 21 23
This article is contributed by Aditya Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Minimum Increment / decrement to make array elements equal
- Count elements such that there are exactly X elements with values greater than or equal to X
- Check whether it is possible to make both arrays equal by modifying a single element
- Get maximum items when other items of total cost of an item are free
- Sum of width (max and min diff) of all Subsequences
- Sorting array elements with set bits equal to K
- Rearrange an array to maximize i*arr[i]
- Maximizing the elements with a[i+1] > a[i]
- Find K items with the lowest values
- Find the k largest numbers after deleting the given elements
- Minimum boxes required to carry all gifts
- Permutation of an array that has smaller values from another array
- Print array elements in alternatively increasing and decreasing order
- Rearrange all elements of array which are multiples of x in increasing order