3.3. Binary-Search-Based Merge to Add the Sort Margin
-
Instead of qsorting the sort margin in, keep it sorted and
then use a binary-search based merge to merge it with the
main array.
-
The reason I used a binary search based merge, instead of a
linear merge, is because I reasoned that the main array
would become much larger than the margin (which has a constant
size), and so this would result in a lot of comparisons.
-
O(log(n)) lookup, O(n) insertion, and O(n2)
accumulative complexity.
-
Noticeably faster than qsorting.
Written by Shlomi Fish