Skip to content

Histogram Sort

Count keys in ordered buckets, compute their offsets, distribute the items, and sort within each bucket.

Core Idea

In the sequential histogram sort described by NIST, a bucket-sort refinement first counts how many input items belong in each ordered bucket. Cumulative counts determine where those buckets begin in an output array; a distribution pass places items in their bucket ranges; and each bucket is then sorted internally. NIST lists interpolation sort as another name for this method.[1][2]

The bucket assignment must respect the desired key order: items assigned to an earlier bucket must not exceed items assigned to a later bucket. After distribution, sorting each bucket and reading them in bucket order yields a globally sorted result. The bucket-local sort is still necessary when a bucket contains distinct keys.[1]

How would you explain it like I'm…

Count, Box, Then Tidy

You have a big pile of numbered cards. First you count how many cards go in each box: small numbers, middle numbers, big numbers. Then you know how much room each box needs on the shelf, put every card in its box's spot, and tidy each box. Now the whole row is in order!

Count-First Bucket Sort

Histogram sort is a way for a computer to put things in order using buckets. First it counts how many items belong in each bucket, like counting how many test scores are in the 60s, 70s, 80s and 90s. Those counts tell it where each bucket's section starts in the final list. Then it places every item into its bucket's section. Last, it sorts the items inside each bucket, because scores like 82 and 87 are in the same bucket but still need ordering.

Count-and-Place Bucket Sort

Histogram sort is a refinement of bucket sort. The buckets are ordered, so everything in an earlier bucket is no larger than anything in a later one. In a first pass, the algorithm counts how many items fall in each bucket — a histogram. Running totals of those counts tell exactly where each bucket's block begins in the output array. A second pass drops each item into its bucket's block, and then each block is sorted on its own. Reading the blocks in order gives a fully sorted list; the inner sort is still needed whenever a bucket holds different values.

 

Histogram sort, as described by NIST (which also lists the name interpolation sort), is a sequential bucket-sort variant that sizes its buckets in advance. A counting pass computes how many keys map to each bucket. A prefix sum over those counts gives each bucket's starting offset in the output array, so buckets occupy contiguous, pre-allocated ranges. A distribution pass writes each item into its bucket's range, after which each bucket is sorted internally. Correctness requires an order-respecting bucket mapping: every key assigned to an earlier bucket must be no greater than any key assigned to a later one. Given that, concatenating the internally sorted buckets in bucket order yields a globally sorted array. The local sort cannot be skipped when a bucket contains distinct keys.

Structural Signature

  • Finite input and key order: the items to rearrange and the order sought.
  • Ordered bucket assignment: each key maps to a valid bucket, preserving the required order across buckets.
  • Counts and offsets: a histogram counts items per bucket; prefix totals give each bucket its starting range.
  • Distribution: items are placed into those reserved ranges, updating a placement position as needed.
  • Local ordering and result: each bucket is sorted and the bucket ranges are read in order.

For numeric keys, an interpolation rule can use the observed range to estimate a bucket. A concrete implementation must define the number of buckets and keep every index in range, including the maximum endpoint. If the input is empty or all keys are equal, it must handle that case without dividing by a zero range. These are implementation requirements, not a claim that one formula is mandatory for every histogram-sort variant.

What It Is Not

A histogram alone is not a sorted sequence: counts allocate ranges, while distribution and local ordering complete the method. The NIST description does not require recursively reapplying the same interpolation formula to each nonsingleton bucket. A separate recursive bucket-sort account uses an interpolation rule to split keys into ordered buckets, computes the bounds for each bucket, recursively sorts those buckets and concatenates them. This recursive procedure is a related approach, not a required step of NIST’s histogram procedure.[3][1]

The name does not establish one unconditional time bound. Cost depends on bucket selection, input distribution, the local sorting procedure and implementation. Stability and memory use also depend on the implementation; they cannot be inferred solely from the name.

Scope of Application

The NIST account is a sequential bucket-refinement description. Related parallel algorithms use histograms to help determine partitions before redistributing data. Harsh, Kale and Solomonik study a distinct distributed algorithm that combines sampling with iterative histogramming; its analysis and performance findings apply to that algorithm and its assumptions, not automatically to every sequential histogram sort.[1][4]

Clarity

State the key domain, ordered bucket rule, number of buckets, offset convention and local sorter. Specify handling for empty input, equal keys and boundary values before applying any numeric formula. Distinguish the NIST naming relationship from the exact procedure used by another author.

Manages Complexity

Counting before distribution lets an implementation reserve contiguous output ranges sized to the observed buckets rather than guessing each range’s occupancy. Skew can concentrate work in a few buckets, and auxiliary storage and data movement have their own costs.[1]

Abstract Reasoning

Choose ordered buckets; count each input item’s bucket; compute starting positions from cumulative counts; distribute items while preserving the bucket ranges; and sort within each range. Verify that no item is lost or duplicated and that the bucket rule respects cross-bucket order.

Example

Suppose integer keys are [8, 1, 7, 2] and three buckets cover 1–3, 4–6 and 7–9. Counts are [2, 0, 2], giving zero-based starts [0, 2, 2]. One distribution is [1, 2 | | 8, 7]; sorting within the last bucket gives [1, 2, 7, 8]. This small illustration fixes bucket boundaries explicitly and does not establish a general complexity bound.

Relationships to Other Abstractions

Local relationship map for Histogram SortParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Histogram SortDOMAINDomain-specific abstraction: Sorting Algorithm — is a kind ofSortingAlgorithmDOMAIN

Current abstraction Histogram Sort Domain-specific

Parents (1) — outgoing typed relations

  • Histogram Sort is a kind of Sorting Algorithm Domain-specific

    Histogram sort rearranges a finite input into key order by ordered buckets and local sorting.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Histogram Sort sits in a sparse region of the domain-specific corpus (93rd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (3155 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

Not to Be Confused With

Bucket sort is the broader family in NIST’s description; histogram sort first counts occupancy to locate bucket ranges. Counting sort can be viewed as a special case with one bucket for each possible key value. A recursive interpolation-based bucket sort may redistribute collision buckets repeatedly, but that control flow is not required by the three-pass NIST definition.[1]

References

[1] Paul E. Black, “histogram sort,” Dictionary of Algorithms and Data Structures, National Institute of Standards and Technology, updated 12 February 2019, entry. registry ↩a ↩b ↩c ↩d ↩e ↩f

[2] Paul E. Black, “interpolation sort,” Dictionary of Algorithms and Data Structures, National Institute of Standards and Technology, updated 12 February 2019, entry. registry ↩

[3] Gonnet, Gaston H., and Ricardo Baeza-Yates. (1991). Handbook of Algorithms and Data Structures: In Pascal and C, 2nd ed. Addison-Wesley, § 4.2.3, pp. 176–179. https://lib.ysu.am/open_books/416858.pdf. registry ↩

[4] Vipul Harsh, Laxmikant Kale and Edgar Solomonik, “Histogram Sort with Sampling,” Proceedings of the 31st ACM Symposium on Parallelism in Algorithms and Architectures (2019), doi:10.1145/3323165.3323184; author-hosted paper. registry ↩