OFFSET
1,3
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.
A run in a permutation is a maximal contiguous subsequence that is either strictly increasing or strictly decreasing. For example, the permutation (1,3,2,4) has runs (1,3), (3,2), (2,4), hence 3 runs.
This sequence counts the total number of runs over all heapable permutations of length n.
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, 31 May 2023, Pages 126-137.
Manolopoulos Panagiotis, Python Program
EXAMPLE
For n=4, the heapable permutations are:
(1,2,3,4): always increasing => 1 run.
(1,3,2,4): 1->3 (up), 3->2 (down), 2->4 (up) => 3 runs.
(1,2,4,3): 1->2 (up), 2->4 (up), 4->3 (down) => 2 runs.
(1,4,2,3): 1->4 (up), 4->2 (down), 2->3 (up) => 3 runs.
(1,3,4,2): 1->3 (up), 3->4 (up), 4->2 (down) => 2 runs.
So among the 5 heapable permutations of length 4:
1 permutation has 1 run,
2 permutations have 2 runs,
2 permutations have 3 runs,
for a total of 11 runs.
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Manolopoulos Panagiotis, Sep 16 2025
EXTENSIONS
a(11)-a(15) from Sean A. Irvine, Sep 26 2025
STATUS
approved
