File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -34,4 +34,6 @@ it can also be adapted to sorting large quantities of data that do not
3434fit into main memories. Historically, when data was primarily stored on
3535magnetic tape, versions of bottom up merge sort were absolutely essential.
3636There are recursive "top down" versions of merge sort, shown elsewhere.
37+ There is also a "natural" merge sort which utilises already sorted runs,
38+ also shown elsewhere
3739
Original file line number Diff line number Diff line change 22
33---
44
5+ Natural merge sort is a variation of the merge sort algorithm that
6+ takes advantage of the natural order present in the input array.
7+ Natural merge sort scans through the array to identify naturally
8+ occurring sorted sequences (runs) and merges consecutive pairs of
9+ runs, until a single run remains.
10+
11+ The merge operation is not in-place - it requires O(n) extra space.
12+ A simple solution (used here) is to merge the two sorted sub-arrays
13+ to a temporary array then copy them back to the original array.
14+ Merge uses three pointers/indices that scan from left to right;
15+ one for each of the input sub-arrays and one for the output array.
16+ At each stage the minimum input array element is copied to the
17+ output array and the indices for those two arrays are incremented.
18+ When one input array has been completely copied, any additional
19+ elements in the other input array are copied to the output array.
20+
21+ Natural merge sort is stable meaning the relative order of equal
22+ elements is preserved. In the bottom-up merge sort, shown elsewhere,
23+ the starting point assumes each run is one item long. In practice,
24+ random input data will have many short runs that just happen to be
25+ sorted. In the typical case, the natural merge sort may not need
26+ as many passes because there are fewer runs to merge.
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ a:hover{
1515
1616-----
1717
18- Geeks for Geeks Link: [ ** Iterative Merge Sort** ] [ G4GLink ]
18+ Happy Coders Link: [ ** Natural Merge Sort** ] [ HCLink ]
1919
2020
21- [ G4GLink ] : https://www.geeksforgeeks.org/iterative- merge-sort/
21+ [ HCLink ] : https://www.happycoders.eu/algorithms/ merge-sort/#Natural_Merge_Sort
2222
You can’t perform that action at this time.
0 commit comments