Preprint
Technical Note

This version is not peer-reviewed.

A Technical Note on Write-Efficient Sift-Down in Classical Binary Heaps

Submitted:

14 April 2026

Posted:

15 April 2026

You are already at the latest version

Abstract
The classical binary heap sink operation based on swap has a significant write overhead. We examine two intuitive improvements: swapping siblings (verified via bounded SMT search) and adding a local hint called pref (the hint-assisted variant). In our bounded SMT checks and implementation comparisons, we did not find evidence that these variants provide consistent benefits; PerfView measurements show the hint-assisted variant was slower in most configurations. Our results suggest that reverting to the straightforward hole-based sink is the practical choice for write-efficient implementations
Keywords: 
;  ;  ;  ;  ;  ;  

1. Introduction

The binary heap is a workhorse data structure in priority queues and heap-based algorithms. When you extract the minimum element, the sink step restores heap order by swapping the root down the tree. This process involves a lot of writes.
The motivation for this work comes from a simple observation: a standard swap-based sink performs three assignments per level. You copy the element to a temporary location, move the child up, then place the element. A hole-based sink does one assignment per level instead. For a tree of height O ( log n ) , this adds up to a noticeable constant-factor overhead in write-heavy workloads.
This raises the obvious question: can we do better? Two ideas circulate in algorithmic discussions. One is to reorder sibling nodes during sinking, betting that this will reduce swaps. Another is to use a preference hint to guide child selection. Both sound reasonable. Both need verification.
This paper examines two questions:
1.
Can hard sibling order constraints reduce sink cost in classical binary heaps?
2.
Can a lightweight heuristic cut element assignments while keeping the heap correct?
We checked both systematically. For the first, bounded SMT verification gave a negative result. For the second, we compared the classic hole-based sinking mechanism against the hint-assisted variant and found no runtime advantage for the hint-assisted approach.
Our contributions:
1.
We report a bounded negative result on a sibling-swap heuristic and a hint-assisted sink variant.
2.
We benchmark the hint-assisted variant against the classic swap-based approach; the hint provided no consistent speedup in our tests.

3. Bounded Negative Result on a Sibling-Swap Heuristic

This section addresses the first question raised in the introduction: whether hard sibling order constraints can reduce sink cost in classical binary heaps.

3.1. Motivation

Picture a small binary heap after an extract-min operation. The last element moves to the root and must sink down. The order of the two children under a parent can affect how many steps this takes.
Consider the array [57, 21, 27, 46] after moving the last element to the root. Here 57 is the root, 21 and 27 are its children, and 46 is the left child of 21. If we swap the siblings 21 and 27, the array becomes [57, 27, 21, 46]. Now sinking 57: it compares with 27 and 21, picks the smaller (21), and swaps. After the swap, 57 sits at position 21, with only 46 as a child. Since 57 ≤ 46, the sink stops. Without swapping siblings, 57 would have swapped with 21, then compared with 46 and swapped again, needing one extra swap.
This example led to a natural proposal: preemptively reorder sibling nodes based on their values to reduce swaps during sinking. But in classical heap semantics, sibling order is not part of the heap invariant. The swap sequence depends on subtree structures and element distribution, not just local sibling ordering.

3.2. Bounded SMT Verification

We encoded the problem in SMT-LIB using cvc5 to check whether sibling swapping can reduce sink cost. The model includes:
  • H: array representation of the heap (1-indexed)
  • Hswapped(H, i): array after swapping node i’s left and right children
  • Heap invariants: parent ≤ left child, parent ≤ right child
  • sink_depth(H, pos, x, n): number of swaps to sink element x at position pos in a heap of size n
Within the searched space ( n 7 ), we did not find evidence that swapping siblings reliably reduces sink steps. The solver returned unsat for all valid heaps of size up to 7, meaning no counterexample exists where sibling swapping changes sink depth. This bounded result suggests sibling ordering is unlikely to help in general.
Appendix A contains the full SMT-LIB encoding used for this verification.
Having found no evidence for sibling-swapping benefits within our bounded search, we now turn to the second question regarding per-step cost reduction.

4. Classical Hole-Based Sink and a Hint-Assisted Variant

This section first describes the classical hole-based sink (our baseline), and then presents a hint-assisted variant that builds upon the hole-based mechanism by adding a pref array. For brevity, we refer to this hint-assisted variant as HHS (a convenient abbreviation).

4.1. Classical Hole-Based Sink

The classic sink operation in extract-min swaps the current node with its smaller child repeatedly until heap order is restored. We first describe the classical hole-based sift-down mechanism, which forms the baseline for our comparison.
The hole-based approach works as follows:
1.
Store the element to be sunk in a “hole”.
2.
Compare the hole element with its children; shift the smaller child upward.
3.
Repeat until the hole element is smaller than both children (or we reach a leaf).
4.
Place the hole element at the final position.
This cuts array writes to one assignment per level instead of three.

4.2. A Hint-Assisted Variant (HHS)

We also tested a hint-assisted variant (HHS) that remembers which child was last chosen at each node using a preference array pref [ i ] . The idea was that recent choices might stay correct in stable heap regions, potentially cutting comparisons. We included this variant in our evaluation as a point of comparison. HHS is included here solely as a comparison baseline. It is not claimed as a novel contribution of this paper.
Note: This variant is not proposed here as a novel contribution. It represents a seemingly intuitive heuristic occasionally discussed in informal algorithm circles. We include it strictly as a point of comparison to empirically verify whether such a hint provides any measurable benefit.
The pref array stores: 0 for uninitialized, 1 for left child last chosen, 2 for right child last chosen. The algorithm checks the preferred child against its sibling before committing, so correctness holds even if the hint is stale.
HHS uses the same hole-sinking structure but augments child selection with a preference hint. The assignment count per level remains identical to the classical hole-based approach.
Algorithm 1 shows the hint-assisted variant.
Algorithm 1 Extract-min using the evaluated hint-assisted variant (HHS)
 1:
procedure HHS-ExtractMin( A , n , pref )
 2:
       minv A [ 1 ]
 3:
       x A [ n ]
 4:
       n n 1
 5:
       i 1
 6:
      while  left ( i ) n  do
 7:
             l left ( i ) , r right ( i )
 8:
            if  r > n  then
 9:
                   c l
10:
           else if  pref [ i ] 0  then
11:
                   c child indicated by pref [ i ]
12:
                  other sibling of c
13:
                 if  A [ c ] > A [ other ]  then
14:
                        c other
15:
                        pref [ i ] if c = l  then 1 else 2
16:
                 else
17:
                        pref [ i ] if c = l  then 1 else 2
18:
           else
19:
                 if  A [ l ] A [ r ]  then
20:
                        c l
21:
                        pref [ i ] 1
22:
                 else
23:
                        c r
24:
                        pref [ i ] 2
25:
           if  x A [ c ]  then
26:
                 break
27:
         A [ i ] A [ c ]
28:
         i c
29:
     A [ i ] x
30:
    return  minv

4.3. Invariants

Both the hole-based and hint-assisted variants maintain the following invariants:
1.
Heap order invariant: After each extract-min, the array satisfies parent ≤ children.
2.
Hole path invariant: Only the path from the root to the final hole is modified; all other subtrees remain valid heaps.
3.
Child-choice heuristic: pref [ i ] is only a hint; even if outdated, the algorithm compares the two children before committing, so correctness is preserved.

4.4. Complexity Analysis

For the hole-based sinking mechanism:
  • Comparisons: Worst case still O ( log n ) (same as standard heap). In practice, the pref hint may reduce some comparisons in stable heap regions, but no asymptotic improvement is claimed.
  • Assignments: Standard sink performs one swap per level, which equals 3 assignments per level. The hole-based sinking mechanism performs one assignment per level (moving the child up) plus one final assignment, totaling log 2 n + 1 assignments. This is approximately 1 / 3 of the standard heap’s assignments.
  • Space: Extra pref array of size n / 2 for the hint-assisted variant, negligible.

5. Experimental Setup

5.1. Experimental Environment

All experiments were conducted under the following environment:
  • OS: Windows 11
  • Compiler: Visual Studio
  • Profiler: PerfView and TraceEvent 3.0.3

5.2. Implementation

We implemented three variants in C++ with 1-indexed arrays:
  • StandardHeap: swap-based sink (three assignments per level)
  • HoleHeap: classical hole-based sink (one assignment per level)
  • HHSHeap: hint-assisted hole sink with pref array

5.3. Workloads

We tested five input types of size n:
  • Sorted: strictly increasing integers.
  • Reverse: strictly decreasing integers.
  • Repeated: integers modulo 10 (many duplicates).
  • AlmostHeap: a valid heap perturbed by swapping 1% of random pairs.
Sizes tested: 1,024; 4,096; 16,384; 65,536; 262,144; 1,048,576.
Each configuration was repeated 5 times with results averaged.

5.4. Counting Rules

We adopted the following counting conventions in our implementation:
  • Swap: 3 assignments (temp store, move child up, place element).
  • Hole update: pref updates do not count as assignments.
  • Build phase: excluded from extraction-phase statistics.
All algorithmic counts were tracked internally by the implementation. PerfView was used only for runtime observations, not to replace internal counters.

6. Results

Table 1 shows the average comparison and assignment counts for random input. Table 2 shows the PerfView sampled CPU time for the entire program execution.
Figure 1. Comparison counts across different heap sizes.
Figure 1. Comparison counts across different heap sizes.
Preprints 208432 g001
Figure 2. Assignment counts across different heap sizes.
Figure 2. Assignment counts across different heap sizes.
Preprints 208432 g002

6.1. Observations

In our measured workloads:
  • Assignments: The hole-based sinking mechanism reduced assignment counts by approximately 60% across all sizes in our implementation. This is consistent with replacing swaps with single writes along the hole path.
  • Comparisons: We did not observe a reduction in comparison counts for either variant within the tested configurations.
  • Runtime: In our PerfView CPU sampling over the entire program execution, the HHS variant consumed more CPU time than the standard swap-based heap. The overhead of the hint logic outweighed any reduction in assignment count.
  • Other input types: Sorted, reverse, repeated, and almost-heap inputs showed similar patterns.
In our PerfView CPU sampling over the entire program execution, the HHS variant consumed more CPU time than the standard swap-based heap. The overhead of the hint logic outweighed any potential benefits.
Due to version constraints of PerfView 3.0.3, hardware counter data was collected in separate runs, but the consistent trend in CPU sampling time provides sufficient evidence for our runtime conclusions.
For completeness, the relative changes for Sorted, Reverse, Repeated, and AlmostHeap inputs followed similar patterns to the Random results. Across all tested types and sizes, HHS exhibited higher CPU time than the standard swap-based heap, while the hole-based sink remained the fastest variant.

7. Discussion

7.1. Why Sibling Swap Does Not Help

Within the searched space ( n 7 ), we did not find evidence that sibling swapping reduces sink steps. This SMT verification is a bounded check: the conclusion is strictly limited to heap sizes up to 7 nodes. We cannot claim that no counterexample exists for larger heaps.
That said, why might this negative result generalize? The sink path at each level is determined by which child holds the smaller value. A sibling swap exchanges the positions of the two children but does not change which subtree contains the smaller value. Since the sink depth depends on the sequence of minima encountered along the path, not on the left-right labeling of those minima, local sibling reordering cannot alter the global sink trajectory in a way that consistently reduces steps.
While a counterexample might theoretically exist for larger heaps, the local nature of the sibling swap makes it structurally unlikely to alter the global sink trajectory in a way that consistently reduces steps.

7.2. Why HHS Did Not Improve End-to-end Runtime

The hint-assisted variant (HHS) is presented here as a negative result; it does not constitute a recommended optimization over the classic hole-based approach.
Several factors explain why HHS did not show runtime improvements despite reducing assignments:
  • Branch overhead: The pref check adds conditional branches, which may reduce instruction-level parallelism on modern out-of-order processors.
  • Memory access: The pref array adds an extra memory read per level, which can trigger cache misses and consume bandwidth.
  • Short paths: The heap height is O ( log n ) , which is relatively short even for large n. The absolute number of assignments saved is limited, so hint maintenance overhead dominates.
  • Modern CPU characteristics: On out-of-order cores with deep pipelines, the reduced assignment count does not translate to proportional performance gains or bandwidth reduction.
In contrast, the classical hole-based sink achieves its reduction through structural elimination of redundant writes (from 3 to 1 per level), providing a deterministic constant-factor improvement without heuristic overhead.
The classical hole-based sink remains the stable and recommended engineering baseline for write-efficient heap implementations.

7.3. Comparison with Related Work

  • Weak heap [2] changes the data structure and requires extra bits. This work stays strictly within the classical heap model.
  • Cache-conscious heaps [3] focus on memory layout. The hole-based approach is complementary and focuses on write reduction.
  • Floyd’s heap construction [1] builds heaps bottom-up. Our work focuses on the sink operation.

7.4. Limitations

Both the hole-based and hint-assisted variants have the following limitations:
  • Neither variant improves asymptotic complexity; they are engineering optimizations.
  • For very small heaps ( n < 8 ), the overhead of maintaining pref may outweigh the benefits, but such heaps are rarely performance-critical.
  • The hint-assisted variant showed higher runtime overhead than the classic hole-based approach in our measurements, so it should be regarded as a negative result rather than a recommended optimization.
HHS should be viewed as an experimental heuristic for evaluation rather than a recommended production optimization. To the best of our knowledge, we are not aware of anyone having published the pref variant heap as a standalone algorithm.

8. Conclusion

We examined two questions about heap sinking:
1.
Bounded SMT verification ( n 7 ) did not show that sibling swapping provides stable reduction in sink steps.
2.
The hint-assisted variant (HHS) did not show end-to-end runtime advantages in our measurements. It should be regarded as a negative result.
3.
The classical hole-based sink is a reliable write-efficient baseline, cutting assignments by approximately 60% without changing asymptotic complexity.
Future work may explore further analysis of write costs in other heap variants.

Appendix A. cvc5 Verification Code

The SMT-LIB code for the bounded negative result:Preprints 208432 i001

Appendix B. C++ Implementation of StandardHeap

Complete C++17 implementation of StandardHeap:
Preprints 208432 i002
Preprints 208432 i003
Preprints 208432 i004
Preprints 208432 i005

Appendix C. C++ Implementation of HHSHeap

Complete C++17 implementation of HHSHeap:
Preprints 208432 i006
Preprints 208432 i007
Preprints 208432 i008
Preprints 208432 i009
Preprints 208432 i010
The implementation of the pure hole-based sink (HoleHeap) follows directly from the HHSHeap code in Appendix C by removing the pref array and all associated hint logic (i.e., simplifying the child selection to a direct comparison between left and right children without preference tracking). For brevity, the full listing is omitted but can be trivially derived.

References

  1. Floyd, R. W. Algorithm 245: Treesort. Communications of the ACM 1964, 7(12), 701. [Google Scholar] [CrossRef]
  2. Dutton, R. D. Weak heaps: A family of efficient priority queues. Software: Practice and Experience 1993, 23(6), 659–678. [Google Scholar]
  3. LaMarca, A.; Ladner, R. E. The influence of caches on the performance of heaps. ACM Journal of Experimental Algorithmics 1996, 1, 4–es. [Google Scholar] [CrossRef]
  4. Parvizi, K. Adaptive cache-friendly priority queue: Enhancing heap-tree efficiency for modern computing. arXiv 2023, arXiv:2310.06663. [Google Scholar]
  5. Toroslu, I. H. Improving the Floyd-Warshall all pairs shortest paths algorithm. arXiv 2021, arXiv:2109.01872. [Google Scholar] [CrossRef]
  6. Cormen, T. H.; Leiserson, C. E.; Rivest, R. L.; Stein, C. Introduction to Algorithms, 3rd ed.; MIT Press, 2009. [Google Scholar]
Table 1. Random input – comparisons and assignments
Table 1. Random input – comparisons and assignments
n Std Cmp HHS Cmp Δ Cmp Std Asn HHS Asn Δ Asn
1,024 15,411.2 15,404.8 0.04 % 23,674.6 9,597.2 59.5 %
4,096 77,955.2 77,940 0.02 % 119,157 46,538 60.9 %
16,384 377,390 377,409 + 0.005 % 574,960 218,979 61.9 %
65,536 1.77 × 10 6 1.77 × 10 6 0 % 2.69 × 10 6 1.01 × 10 6 62.5 %
262,144 8.13 × 10 6 8.13 × 10 6 0 % 1.23 × 10 7 4.55 × 10 6 63.0 %
1,048,576 3.67 × 10 7 3.67 × 10 7 0 % 5.57 × 10 7 2.03 × 10 7 63.6 %
Table 2. Random input – PerfView sampled CPU time over the entire program execution
Table 2. Random input – PerfView sampled CPU time over the entire program execution
Standard Heap HHS
CPU time (ms) 33,659 44,728
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.
Prerpints.org logo

Preprints.org is a free preprint server supported by MDPI in Basel, Switzerland.

Subscribe

Disclaimer

Terms of Use

Privacy Policy

Privacy Settings

© 2026 MDPI (Basel, Switzerland) unless otherwise stated