Block Merge Sort

Block Merge Sort (a.k.a. Block Sort) is a stable worst case $$O(n \log n)$$ time sorting algorithm using $$O(1)$$ extra space. Given the time and space bounds, this makes Block Merge Sort less trivial than most other algorithms such as Heapsort (which is in-place but not stable) or Mergesort (which is stable but not in-place) or Rotate Merge Sort (which is stable and in-place but $$O(n \log^2 n)$$). There also exists Block Merge variants that allocate some extra space such as $$O(\sqrt{n })$$ or $$O(\log n)$$ space.

In brief, Block Merge Sort divides the array into smaller evenly sized sections called "blocks." It then merges the array each block at a time by using specialized techniques such as a blocked Selection Sort to sort the blocks and a modified Insertion Sort for finding distinct elements to use as merge space in the array itself. For convenience and sake of $$O(1)$$ space implementations, the best choice for the block size is $$O(\sqrt{n })$$ but some variants use different block sizes such as $$O(\sqrt[3]{n })$$ or $$O(\log n)$$.

Although Block Merge boasts an in-place stable $$O(n)$$ time merge, it's not the fastest in-place merge in practice and is beaten by Rotate Merge which is a suboptimal $$O(n \log n)$$ merge. This is possibly due to the complicated nature of Block Merge as well as its high overhead and poorer cache utilization.

Algorithm
Block Merge sorts are a class of sorting algorithms that share these qualities: They are Stable, In-Place (sometimes), and $$O(n \log n)$$. They always take the form of a bottom-up merge sort, and extensively use $$O(\sqrt{n})$$ "blocks" and unique buffers. Their merge usually consists of two stages: Merging, where a unique buffer is used to merge individual $$O(\sqrt{n})$$ blocks, and Block Selection, where the blocks are sorted with a variant of Selection Sort that sorts the blocks using their first/last element as the key. Because Selection Sort is not stable, there is also another unique buffer that either "tags" the blocks or imitates their movement to force stability. Cycle Sort can also be used. Some Block Merge sorts use $$O(\sqrt{n})$$ external buffers, making them not In-Place, though they do not have to make sure that elements are unique, as the buffers can be overwritten at will. Block Selection and Merging can be done in any order: Selection before Merging (Grail), Selection at the same time as Merging (Wiki), or Selection after Merging (Kota).

Wiki Sort
Main Page: Wikisort

Grail Sort
Main Page: Grailsort

Kota Sort
Main Page: Kotasort