Papers
Topics
Authors
Recent
Search
2000 character limit reached

Topological Heapsort: Heap-Based Topological Sorting

Updated 6 July 2026
  • 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 O(nlog2n)\mathcal{O}(n\log^2 n) 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 vv of a DAG GG carries an integer key v.labelv.\mathrm{label}, and the multiset of current labels is labels(G)\mathrm{labels}(G). For a directed edge (uv)(u \to v), the edge is good if u.labelv.labelu.\mathrm{label} \le v.\mathrm{label} and bad otherwise. A labeled DAG is ordered if all edges are good. This is the DAG generalization of the min-heap property. When GG has exactly one source vertex ss, that source necessarily stores the minimum label in any ordered DAG, because every reachable vertex has label at least s.labels.\mathrm{label} (Gudim, 2017).

Insertion is generalized by the procedure vv0 for vv1. The label at vv2 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 vv3 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 vv4 of the current vertex and any next neighbor vv5 of the current vertex, vv6 (Gudim, 2017).

This yields a priority queue interface for any single-source DAG. The constructor initializes all labels to vv7 and maintains a stateful iterator vv8 that returns vertices in breadth-first order from the source. The operations are:

  • vv9: take the next vertex and call GG0,
  • GG1: return the source,
  • GG2: call GG3 on the source with GG4,
  • decrease-key and increase-key: invoke GG5 and GG6 on arbitrary vertices.

If GG7 is the length of the longest simple directed path from the source, and GG8 and GG9 are the maximum in-degree and out-degree, then

v.labelv.\mathrm{label}0

with v.labelv.\mathrm{label}1. Sorting by v.labelv.\mathrm{label}2 inserts followed by v.labelv.\mathrm{label}3 extract-min operations gives

v.labelv.\mathrm{label}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 v.labelv.\mathrm{label}5-dimensional hypercube DAG. Its vertices are the v.labelv.\mathrm{label}6 subsets of a v.labelv.\mathrm{label}7-element set, and an edge is directed from v.labelv.\mathrm{label}8 to v.labelv.\mathrm{label}9 when labels(G)\mathrm{labels}(G)0 is obtained from labels(G)\mathrm{labels}(G)1 by adding one element. The unique source is the empty set labels(G)\mathrm{labels}(G)2. A vertex of cardinality labels(G)\mathrm{labels}(G)3 has in-degree labels(G)\mathrm{labels}(G)4, out-degree labels(G)\mathrm{labels}(G)5, and every path from the source to that vertex has length labels(G)\mathrm{labels}(G)6. Globally, labels(G)\mathrm{labels}(G)7, labels(G)\mathrm{labels}(G)8, and the number of vertices is labels(G)\mathrm{labels}(G)9, so (uv)(u \to v)0 (Gudim, 2017).

Substituting these parameters into the general bound gives

(uv)(u \to v)1

The paper also gives an exact worst-case bound for insertion comparisons when (uv)(u \to v)2:

(uv)(u \to v)3

For general (uv)(u \to v)4, one may choose (uv)(u \to v)5 such that (uv)(u \to v)6 and embed into the next power-of-two hypercube; the asymptotic bound remains (uv)(u \to v)7 (Gudim, 2017).

The same paper derives a structural inequality for any single-source DAG with (uv)(u \to v)8 vertices:

(uv)(u \to v)9

This is obtained by combining the lower bound u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}0 for comparison-based sorting with the ordered-DAG sorting upper bound u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}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 u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}2 items and u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}3 pre-existing binary comparisons, represented by a DAG u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}4. The unknown total order is promised to be a linear extension of the partial order induced by u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}5, and u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}6 denotes the number of linear extensions, equivalently the number of topological orders of u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}7. The information-theoretic lower bound is u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}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 u.labelv.labelu.\mathrm{label} \le v.\mathrm{label}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 GG0 amortized time, and GG1 of item GG2 in GG3 amortized time, where GG4 is the maximum size of GG5’s working set. Appropriately used pairing heaps and splay-as-heap variants are cited as examples. The base algorithm runs in GG6 time and performs GG7 comparisons. Its analysis models heap residency intervals by an interval graph, greedily partitions that graph into cliques, proves a lower bound on GG8 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 GG9 term in the comparison count, the paper introduces “Topological Heapsort with Insertion.” It first computes and compresses a longest path ss0, stores the original path in an array ss1, and runs the base Topological Heapsort on a reduced DAG ss2. Each extracted off-path vertex is then inserted into the evolving sorted list ss3 by exponential search followed by binary search. The paper proves that this variant sorts in ss4 time and ss5 comparisons, which is optimal up to constant factors. It also notes that the algorithm can be modified to stop after ss6 outputs for the top-ss7 problem, although no explicit theorem with exact top-ss8 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, ss9 time and s.labels.\mathrm{label}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 s.labels.\mathrm{label}1 vertices, then s.labels.\mathrm{label}2. The second is an interval-embedding argument that bounds s.labels.\mathrm{label}3 by s.labels.\mathrm{label}4. Algorithmically, the paper extracts a longest path s.labels.\mathrm{label}5, locates for each source the farthest in-neighbor s.labels.\mathrm{label}6 on s.labels.\mathrm{label}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 s.labels.\mathrm{label}8 and sorting s.labels.\mathrm{label}9 time and comparisons, and then a final algorithm with preprocessing vv00 and sorting vv01 time and comparisons. The key data structure is a Unified Bound Heap with vv02 in amortized vv03 time, first vv04 in amortized vv05 time, and subsequent pop of vv06 in amortized

vv07

where vv08 is the push index and vv09 is the pop index. A longest-path reduction compresses the sorting phase to a subset vv10 with vv11, after which only vv12 is sorted and the full order is reconstructed in vv13 time (Rutschmann, 14 Apr 2026).

The antimatroid generalization broadens the scope further. In “Optimal antimatroid sorting,” the allowable orders form vv14 for an antimatroid vv15 on a ground set vv16, and the frontier becomes

vv17

Topological Heapsort is obtained by replacing DAG sources with this frontier and by using a candidate data structure vv18 to maintain newly available elements. The queue time is vv19 for a monotone precedence system vv20, and a refined algorithm based on layers, bottlenecks, trace antimatroids, and an antimatroid-aware merge achieves time vv21 with vv22 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 vv23 insertion and extraction cost and vv24 sorting time. HypercubeSort has vv25 per operation and vv26 comparisons. By contrast, sorting under partial information can be much easier than unrestricted sorting: if the number of feasible total orders is vv27 or vv28, the lower bound is vv29 or vv30, 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 vv31 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 vv32 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).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Topological Heapsort.