OFFSET
1,4
COMMENTS
A permutation of [1..n] is heapable if it can be inserted, one element at a time, into a binary min-heap without violating the heap property.
An inversion in a permutation p of length n is a pair of indices (i,j) with i<j such that p(i)>p(j).
The total number of inversions is the number of such pairs.
LINKS
Benjamin Chen, Michael Cho, Mario Tutuncu-Macias, and Tony Tzolov, Efficient methods of calculating the number of heapable permutations, Discrete Applied Mathematics Volume 331 (2023), 126-137.
Manolopoulos Panagiotis, Python program
EXAMPLE
For n=4, the heapable permutations are:
(1,2,3,4): no inversions 0.
(1,3,2,4): pair (2,3) 1 inversion.
(1,2,4,3): pair (3,4) 1 inversion.
(1,4,2,3): pairs (2,3),(2,4) 2 inversions.
(1,3,4,2): pairs (2,4),(3,4) 2 inversions.
So the total number of inversions across all 5 heapable permutations of length 4 is: 0+1+1+2+2=6.
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Manolopoulos Panagiotis, Oct 14 2025
EXTENSIONS
a(11)-a(16) from Sean A. Irvine, Oct 21 2025
STATUS
approved
