Ranking and Unranking Permutations in Heap's Order
Yusheng Hu
Key points
From the paper's conclusion- The Heap order is in fact the colex order of the mixed-radix code.
Abstract
Heap's algorithm is a permutation generation method with very low constant overhead. Its element-interchanging mechanism, however, prevents the standard factorial-base Lehmer code from being applied directly, and to our knowledge no explicit Rank/Unrank algorithm for the Heap order has been published. This paper describes the block structure of Heap's algorithm in terms of rearrangement operators: the net effect of a block-internal traversal is a tail-preserving operator and the block-boundary swap is a top-level swap operator, and together they yield a closed-form recurrence for the block transitions. On this basis a bottom-up Unrank algorithm and a top-down Rank algorithm are built from one and the same closed-form in-block mapping; both run in $O(n^3)$ time and $O(n)$ space and require no factorial-scale precomputed table. The supporting proofs use a synchronized strong induction on the dimension to establish the bijectivity of the trailing-element mapping, closed forms for the final arrangement and for the trailing sequence, the dichotomy of its cycle structure, and the reciprocity of Rank and Unrank. The Heap order is in fact the colex order of the mixed-radix code.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Heap-type permutation generation with a prescribed final arrangementarXiv · 2026
- A Geometric Derivation of the Bitner--Ehrlich--Reingold Loopless Gray Code AlgorithmarXiv · 2026
- Unranking $S$-avoiding permutations with two forbidden offsetsarXiv · 2026
- Iterating the Lehmer code on inversion sequences: Catalan fixed points and finite stabilizationarXiv · 2026
- Sorting by block-reversals: closing the gaparXiv · 2026
- Faster polynomial-space algorithms for poset problemsarXiv · 2026