Topological Heapsort: Heap-Based Topological Sorting
- Topological Heapsort is a family of algorithms that generalize the heap property to directed acyclic graphs with a unique source, ensuring edge-wise monotonicity.
- In hypercube implementations, it exhibits a tradeoff between longest-path length and vertex degrees, achieving O(n log² n) comparisons in the worst-case scenario.
- Extensions to partial-information sorting leverage antimatroid frontiers and working-set heaps to match information-theoretic lower bounds with efficient frontier maintenance.
Topological Heapsort denotes a family of comparison-based methods that combine heap-style minimum extraction with a topological or partially ordered structure. In one formulation, developed in “Ordered Dags: HypercubeSort,” a binary heap is generalized to any directed acyclic graph with a single source, yielding a priority queue interface and, for the hypercube DAG, a sorting algorithm with comparisons. In a later formulation for sorting under partial information, the feasible frontier of a DAG, and later of an antimatroid, is maintained in a heap ordered by an unknown linear extension, so that the number of comparisons can match the information-theoretic lower bound up to constant factors (Gudim, 2017, Haeupler et al., 2024, Berendsohn, 18 Jul 2025, Rutschmann, 14 Apr 2026).
1. Terminological scope and conceptual core
The term appears in two technically distinct contexts. In the 2017 ordered-DAG framework, the central object is a labeled DAG with one source vertex, and the heap property is replaced by an edge-wise monotonicity invariant: for a min-structure, labels never decrease along edges. In the 2024–2026 line on sorting under partial information, Topological Heapsort combines Kahn-style maintenance of current sources with a heap whose comparator queries an oracle for an unknown total order extending the input DAG. The 2025 antimatroid generalization replaces DAG sources by the antimatroid frontier of currently available elements (Gudim, 2017, Haeupler et al., 2024, Berendsohn, 18 Jul 2025).
These formulations share a common structural theme. The admissible next outputs are constrained by a directed or feasible-order topology, while local comparisons determine which admissible element is extracted next. This shared pattern explains the name: the algorithmic control flow is topological, but the selection policy is heap-like.
A persistent source of confusion is the relationship to ordinary topological sorting. Ordinary topological sorting outputs any order consistent with a DAG and requires no key comparisons. Topological Heapsort, in contrast, uses a DAG or a more general feasibility system as a constraint structure while still performing comparison-based sorting. In the ordered-DAG formulation, the keys are arbitrary labels stored on vertices. In the partial-information formulation, the output is the unknown linear extension singled out by oracle comparisons among currently feasible elements (Gudim, 2017, Haeupler et al., 2024).
2. Ordered DAGs as generalized heaps
In the ordered-DAG formulation, every vertex of a DAG carries an integer key , and the multiset of current labels is . For a directed edge , the edge is good if and bad otherwise. A labeled DAG is ordered if all edges are good. This is the DAG generalization of the min-heap property. When has exactly one source vertex , that source necessarily stores the minimum label in any ordered DAG, because every reachable vertex has label at least (Gudim, 2017).
Insertion is generalized by the procedure 0 for 1. The label at 2 is decreased, and any resulting violation is repaired by repeatedly choosing the largest violating previous neighbor, exchanging labels, and continuing from that predecessor. The procedure terminates because the DAG is finite and acyclic, and each swap moves the current vertex strictly upward toward the source. The symmetric operation 3 increases a key by swapping downward with the smallest violating next neighbor. The ordered-DAG invariant maintained by the paper has two parts: all bad edges, if any, enter the current vertex, and for any previous neighbor 4 of the current vertex and any next neighbor 5 of the current vertex, 6 (Gudim, 2017).
This yields a priority queue interface for any single-source DAG. The constructor initializes all labels to 7 and maintains a stateful iterator 8 that returns vertices in breadth-first order from the source. The operations are:
- 9: take the next vertex and call 0,
- 1: return the source,
- 2: call 3 on the source with 4,
- decrease-key and increase-key: invoke 5 and 6 on arbitrary vertices.
If 7 is the length of the longest simple directed path from the source, and 8 and 9 are the maximum in-degree and out-degree, then
0
with 1. Sorting by 2 inserts followed by 3 extract-min operations gives
4
The framework therefore generalizes heapsort from complete binary trees to arbitrary single-source DAG topologies (Gudim, 2017).
3. HypercubeSort and the path–degree tradeoff
The hypercube instantiation specializes the ordered-DAG framework to the 5-dimensional hypercube DAG. Its vertices are the 6 subsets of a 7-element set, and an edge is directed from 8 to 9 when 0 is obtained from 1 by adding one element. The unique source is the empty set 2. A vertex of cardinality 3 has in-degree 4, out-degree 5, and every path from the source to that vertex has length 6. Globally, 7, 8, and the number of vertices is 9, so 0 (Gudim, 2017).
Substituting these parameters into the general bound gives
1
The paper also gives an exact worst-case bound for insertion comparisons when 2:
3
For general 4, one may choose 5 such that 6 and embed into the next power-of-two hypercube; the asymptotic bound remains 7 (Gudim, 2017).
The same paper derives a structural inequality for any single-source DAG with 8 vertices:
9
This is obtained by combining the lower bound 0 for comparison-based sorting with the ordered-DAG sorting upper bound 1. The result formalizes a tradeoff between shallowness and degree: reducing the longest-path length forces high in-degree or out-degree, while bounding degrees forces the DAG to be deep. In the ordered-DAG setting, this tradeoff directly controls insertion and extraction cost (Gudim, 2017).
4. Sorting under partial information on DAGs
A separate line of work studies sorting under partial information. The input consists of 2 items and 3 pre-existing binary comparisons, represented by a DAG 4. The unknown total order is promised to be a linear extension of the partial order induced by 5, and 6 denotes the number of linear extensions, equivalently the number of topological orders of 7. The information-theoretic lower bound is 8 comparisons (Haeupler et al., 2024).
In this setting, Topological Heapsort combines two classical ideas. Classical topological sorting maintains the frontier of current sources, while heapsort repeatedly extracts a minimum from a heap. The algorithm keeps exactly the current sources in a working-set heap ordered by the unknown total order. At each step it performs 9 on the heap, outputs that source, deletes its outgoing arcs by decrementing in-degrees, and inserts any vertices whose in-degree becomes zero. Comparisons occur only among sources, because only sources can be next in any linear extension (Haeupler et al., 2024).
The heap requirement is a working-set bound: insert in 0 amortized time, and 1 of item 2 in 3 amortized time, where 4 is the maximum size of 5’s working set. Appropriately used pairing heaps and splay-as-heap variants are cited as examples. The base algorithm runs in 6 time and performs 7 comparisons. Its analysis models heap residency intervals by an interval graph, greedily partitions that graph into cliques, proves a lower bound on 8 in terms of the clique sizes, and then bounds the total working-set cost by the same clique expression (Haeupler et al., 2024).
To remove the additive 9 term in the comparison count, the paper introduces “Topological Heapsort with Insertion.” It first computes and compresses a longest path 0, stores the original path in an array 1, and runs the base Topological Heapsort on a reduced DAG 2. Each extracted off-path vertex is then inserted into the evolving sorted list 3 by exponential search followed by binary search. The paper proves that this variant sorts in 4 time and 5 comparisons, which is optimal up to constant factors. It also notes that the algorithm can be modified to stop after 6 outputs for the top-7 problem, although no explicit theorem with exact top-8 bounds is stated (Haeupler et al., 2024).
5. Optimal refinements and generalization beyond posets
“Simpler Optimal Sorting from a Directed Acyclic Graph” proves the same asymptotic guarantees, 9 time and 0 queries, but replaces the earlier sophisticated analysis by two brief observations. The first is a longest-path lemma: if a longest directed path has 1 vertices, then 2. The second is an interval-embedding argument that bounds 3 by 4. Algorithmically, the paper extracts a longest path 5, locates for each source the farthest in-neighbor 6 on 7, and uses finger-search insertions guided by the oracle to place the source into the evolving order. The result matches the bounds of the earlier Topological Heapsort line while avoiding advanced charging arguments and sophisticated data structures (Hoog et al., 2024).
“Sorting under Partial Information with Optimal Preprocessing Time via Unified Bound Heaps” strengthens the preprocessing–query tradeoff. It gives a simple two-phase algorithm, UniTopSort, with preprocessing 8 and sorting 9 time and comparisons, and then a final algorithm with preprocessing 00 and sorting 01 time and comparisons. The key data structure is a Unified Bound Heap with 02 in amortized 03 time, first 04 in amortized 05 time, and subsequent pop of 06 in amortized
07
where 08 is the push index and 09 is the pop index. A longest-path reduction compresses the sorting phase to a subset 10 with 11, after which only 12 is sorted and the full order is reconstructed in 13 time (Rutschmann, 14 Apr 2026).
The antimatroid generalization broadens the scope further. In “Optimal antimatroid sorting,” the allowable orders form 14 for an antimatroid 15 on a ground set 16, and the frontier becomes
17
Topological Heapsort is obtained by replacing DAG sources with this frontier and by using a candidate data structure 18 to maintain newly available elements. The queue time is 19 for a monotone precedence system 20, and a refined algorithm based on layers, bottlenecks, trace antimatroids, and an antimatroid-aware merge achieves time 21 with 22 comparisons. The paper gives optimal algorithms for monotone precedence formulas, perfect elimination orders of chordal graphs, and vertex search orders of a connected rooted graph; it also states that the transcript of Dijkstra’s algorithm matches Topological Heapsort’s transcript on the vertex search antimatroid, yielding a universal-optimality interpretation (Berendsohn, 18 Jul 2025).
6. Relations, distinctions, and limitations
Topological Heapsort is not topological sorting. In the DAG and antimatroid restricted-sorting literature, the partial order or feasibility system narrows the set of admissible next outputs, but comparisons are still necessary to recover the unknown linear extension. In the ordered-DAG formulation, the DAG is not the input partial information at all; it is a container whose local edge-wise invariant generalizes the heap property. These are related uses of the same phrase, but they solve different algorithmic problems (Gudim, 2017, Haeupler et al., 2024).
The comparison to classical heapsort also depends on the formulation. Binary heaps give 23 insertion and extraction cost and 24 sorting time. HypercubeSort has 25 per operation and 26 comparisons. By contrast, sorting under partial information can be much easier than unrestricted sorting: if the number of feasible total orders is 27 or 28, the lower bound is 29 or 30, and the DAG-based and antimatroid-based Topological Heapsort algorithms achieve matching upper bounds up to constant factors (Gudim, 2017, Haeupler et al., 2024, Berendsohn, 18 Jul 2025, Rutschmann, 14 Apr 2026).
Several practical and theoretical caveats recur. In the ordered-DAG framework, the single-source condition is required to identify a unique minimum position and support 31 peek; multiple sources would complicate minimum handling. Equal labels are allowed, but stability is not guaranteed unless additional tie-breaking is enforced. In the partial-information and antimatroid settings, optimality depends on efficient maintenance of the frontier; beyond antimatroids, the 2025 paper states that Topological Heapsort is not optimal in general greedoids, and it lists efficient candidate data structures for richer antimatroids such as convex shellings as an open direction. The 2026 paper similarly identifies dynamic DAGs and simpler heaps achieving the unified bound as open problems (Gudim, 2017, Berendsohn, 18 Jul 2025, Rutschmann, 14 Apr 2026).
A final distinction concerns other graph-based sorting methods. “Sorting an Array Using the Topological Sort of a Corresponding Comparison Graph” constructs a comparison graph, uses DFS-based topological sorting, Hamiltonian-path arguments, and graph merges, and obtains a stable 32 algorithm. It is topological-sort-based, but it does not use the frontier-maintenance priority-queue paradigm that characterizes the later Topological Heapsort literature. This suggests a broader landscape of graph-structured comparison sorting, within which Topological Heapsort is the heap-oriented strand (Behera, 2020).