Spreadsort
Spreadsort is a sorting algorithm invented by Steven J. Ross in 2002. It combines concepts from distribution-based sorts, such as radix sort and bucket sort, with partitioning concepts from comparison sorts such as quicksort and mergesort. In experimental results it was shown to be highly efficient, often outperforming traditional algorithms such as quicksort, particularly on distributions exhibiting structure and string sorting. There is an open-source implementation with performance analysis and benchmarks, and HTML documentation . Quicksort identifies a pivot element in the list and then partitions the list into two sublists, those elements less than the pivot and those greater than the pivot. Spreadsort generalizes this idea by partitioning the list into n/c partitions at each step, where n is the total number of elements in the list and c is a small constant (in practice usually between 4 and 8 when comparisons are slow, or much larger in situations where they are fast). It uses distribution-based techniques to accomplish this, first locating the minimum and maximum value in the list, and then dividing the region between them into n/c equal-sized bins. Where caching is an issue, it can help to have a maximum number of bins in each recursive division step, causing this division process to take multiple steps.…
Spreadsort is a sorting algorithm invented by Steven J. Ross in 2002. It combines concepts from distribution-based sorts, such as radix sort and bucket sort, with partitioning concepts from comparison sorts such as quicksort and mergesort. In experimental results it was shown to be highly efficient, often outperforming traditional algorithms such as quicksort, particularly on distributions exhibiting structure and string sorting. There is an open-source implementation with performance analysis and benchmarks, and HTML documentation . Quicksort identifies a pivot element in the list and then partitions the list into two sublists, those elements less than the pivot and those greater than the pivot. Spreadsort generalizes this idea by partitioning the list into n/c partitions at each step, where n is the total number of elements in the list and c is a small constant (in practice usually between 4 and 8 when comparisons are slow, or much larger in situations where they are fast). It uses distribution-based techniques to accomplish this, first locating the minimum and maximum value in the list, and then dividing the region between them into n/c equal-sized bins. Where caching is an issue, it can help to have a maximum number of bins in each recursive division step, causing this division process to take multiple steps. Though this causes more iterations, it reduces cache misses and can make the algorithm run faster overall. In the case where the number of bins is at least the number of elements, spreadsort degenerates to bucket sort and the sort completes. Otherwise, each bin is sorted recursively. The algorithm uses heuristic tests to determine whether each bin would be more efficiently sorted by spreadsort or some other classical sort algorithm, then recursively sorts the bin. Like other distribution-based sorts, spreadsort has the weakness that the programmer is required to provide a means of converting each element into a numeric key, for the purpose of identifying which bin it falls in. Although it is possible to do this for arbitrary-length elements such as strings by considering each element to be followed by an infinite number of minimum values, and indeed for any datatype possessing a total order, this can be more difficult to implement correctly than a simple comparison function, especially on complex structures. Poor implementation of this value function can result in clustering that harms the algorithm's relative performance. Experiments were done comparing an optimized version of spreadsort to the highly optimized C++ std::sort , implemented with introsort. On lists of integers and floats spreadsort shows a roughly 2–7× runtime improvement for random data on various operating systems.In space performance, spreadsort is worse than most in-place algorithms: in its simplest form, it is not an in-place algorithm, using O(n) extra space; in experiments, about 20% more than quicksort using a c of 4–8. With a cache-aware form (as included in Boost.Sort), less memory is used and there is an upper bound on memory usage of the maximum bin count times the maximum number of recursions, which ends up being a few kilobytes times the size of the key in bytes. Although it uses asymptotically more space than the O(log n) overhead of quicksort or the O(1) overhead of heapsort, it uses considerably less space than the basic form of mergesort, which uses auxiliary space equal to the space occupied by the list. unsigned RoughLog2(DATATYPE input) { unsigned char cResult = 0; // The && is necessary on some compilers to avoid infinite loops; it doesn't // significantly impair performance if (input >= 0) while ((input >> cResult) && (cResult > cResult) MAX_SPLITS) ? MAX_SPLITS : logSize); // Don't try to bitshift more than the size of an element if (DATA_SIZE piMax) piMax = Array[u]; else if (Array[u] MAX_SPLITS) LogDivisor = logRange - MAX_SPLITS; divMin = iMin >> LogDivisor; divMax = iMax >> LogDivisor; uBinCount = divMax - divMin + 1; // Allocate the bins and determine their sizes BinArray = calloc(uBinCount, sizeof(Bin)); // Memory allocation failure check and clean return with sorted results if (!BinArray) { printf("Using std::sort because of memory allocation failure\n"); std::sort(Array, Array + uCount); return NULL; } // Calculating the size of each bin; this takes roughly 10% of runtime for (u = 0; u > LogDivisor) - divMin].uCount++; // Assign the bin positions BinArray[0].CurrentPosition = (DATATYPE *)Array; for (u = 0; u > LogDivisor) - divMin); (CurrentBin->uCount > u); CurrentBin = BinArray + ((Array[u] >> LogDivisor) - divMin)) SWAP(Array + u, CurrentBin->CurrentPosition++); // Now that we've found the item belonging in this position, // increment the bucket count if (CurrentBin->CurrentPosition == Array + u) ++(CurrentBin->CurrentPosition); } // If we've bucketsorted, the array is sorted and we should skip recursion if (!LogDivisor) { free(BinArray); return NULL; } return BinArray; } void SpreadSortBins(DATATYPE *Array, SIZETYPE uCount, SIZETYPE uBinCount, const DATATYPE &iMax , const DATATYPE &iMin, Bin * BinArray, SIZETYPE uMaxCount) { SIZETYPE u; for (u = 0; u
References
- Steven J. Ross. The Spreadsort High-performance General-case Sorting Algorithm. Parallel and Distributed Processing Techniques and Applications , Volume 3, pp. 1100–1106. Las Vegas Nevada. 2002. Wikipedia revision 1375073415, retrieved 2026-11-19 · retrieved 2026-11-18 · rev 1375073415
Cite this reference
MLA "Steven J. Ross. The Spreadsort High-performance General-case Sorting Algorithm. Parallel and Distributed Processing Techniques and Applications , Volume 3, pp. 1100–1106. Las Vegas Nevada. 2002. Wikipedia revision 1375073415, retrieved 2026-11-19." Steven J. 2026-11-18. https://en.wikipedia.org/w/index.php?oldid=1375073415. Accessed 24 November 2026.
Chicago "Steven J. Ross. The Spreadsort High-performance General-case Sorting Algorithm. Parallel and Distributed Processing Techniques and Applications , Volume 3, pp. 1100–1106. Las Vegas Nevada. 2002. Wikipedia revision 1375073415, retrieved 2026-11-19." Steven J. 2026-11-18. https://en.wikipedia.org/w/index.php?oldid=1375073415.
APA Steven J. (2026). Steven J. Ross. The Spreadsort High-performance General-case Sorting Algorithm. Parallel and Distributed Processing Techniques and Applications , Volume 3, pp. 1100–1106. Las Vegas Nevada. 2002. Wikipedia revision 1375073415, retrieved 2026-11-19. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1375073415
- Boost.Sort github repository · retrieved 2026-11-18 · rev 1375073415
Cite this reference
MLA "Boost.Sort github repository." "Boost. 2026-11-18. https://github.com/boostorg/sort/tree/master. Accessed 24 November 2026.
Chicago "Boost.Sort github repository." "Boost. 2026-11-18. https://github.com/boostorg/sort/tree/master.
APA "Boost. (2026). Boost.Sort github repository. Retrieved November 24, 2026, from https://github.com/boostorg/sort/tree/master
- HTML Spreadsort Documentation · retrieved 2026-11-18 · rev 1375073415
Cite this reference
MLA "HTML Spreadsort Documentation." 2026-11-18. http://www.boost.org/doc/libs/1_65_0/libs/sort/doc/html/index.html. Accessed 24 November 2026.
Chicago "HTML Spreadsort Documentation." 2026-11-18. http://www.boost.org/doc/libs/1_65_0/libs/sort/doc/html/index.html.
APA encyclopegia.org. (2026). HTML Spreadsort Documentation. Retrieved November 24, 2026, from http://www.boost.org/doc/libs/1_65_0/libs/sort/doc/html/index.html
- Two Levels are as Good as Any · retrieved 2026-11-18 · rev 1375073415
Cite this reference
MLA "Two Levels are as Good as Any." Tamminen, Markku (March 1985). 2026-11-18. https://en.wikipedia.org/wiki/Doi_(identifier). Accessed 24 November 2026.
Chicago "Two Levels are as Good as Any." Tamminen, Markku (March 1985). 2026-11-18. https://en.wikipedia.org/wiki/Doi_(identifier).
APA Tamminen, Markku (March 1985). (2026). Two Levels are as Good as Any. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Doi_(identifier)
- Maus, Arne (2002). ARL, a faster in-place, cache friendly sorting algorithm (PDF) (Technical report). Wikipedia revision 1375073415, retrieved 2026-11-19 · retrieved 2026-11-18 · rev 1375073415
Cite this reference
MLA "Maus, Arne (2002). ARL, a faster in-place, cache friendly sorting algorithm (PDF) (Technical report). Wikipedia revision 1375073415, retrieved 2026-11-19." Maus, Arne (2002). 2026-11-18. http://www.nik.no/2002/Maus.pdf. Accessed 24 November 2026.
Chicago "Maus, Arne (2002). ARL, a faster in-place, cache friendly sorting algorithm (PDF) (Technical report). Wikipedia revision 1375073415, retrieved 2026-11-19." Maus, Arne (2002). 2026-11-18. http://www.nik.no/2002/Maus.pdf.
APA Maus, Arne (2002). (2026). Maus, Arne (2002). ARL, a faster in-place, cache friendly sorting algorithm (PDF) (Technical report). Wikipedia revision 1375073415, retrieved 2026-11-19. Retrieved November 24, 2026, from http://www.nik.no/2002/Maus.pdf
Cite this article
MLA
"Spreadsort." encyclopegia.org, 2026, https://encyclopegia.org/wiki/spreadsort. Accessed 24 November 2026.
Chicago
"Spreadsort." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/spreadsort.
APA
encyclopegia.org. (2026). Spreadsort. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/spreadsort
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON