login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A379905
Rank of the permutation resulting from a pre-order traversal of a binary tree which is complete except for the final row and has vertices numbered 0 to n-1.
0
0, 0, 0, 1, 3, 8, 30, 222, 1302, 8442, 63570, 545473, 5249163, 55941128, 653682990, 8597126190, 117809490990, 1730350233390, 27183297753390, 454752069221550, 8070074352360750, 151403473011001710, 2993918729983972590, 62232717584055513822, 1356493891878893498262
OFFSET
1,5
COMMENTS
Permutations are ranked in lexicographic order with the identity permutation as rank 0.
The tree is complete when n = 2^k - 1.
Also the tree has A070939(n) levels and the tree height is floor(log_2(n)).
EXAMPLE
For n = 5, the tree is
0
/ \
1 2
/ \
3 4
Pre-order traversal is vertices {0,1,3,4,2} and among the permutations of 0..4 this has rank a(5) = 3.
PROG
(Python)
from binarytree import Node, build
from sympy.combinatorics import Permutation
a = lambda n: Permutation([node.value for node in build(list(range(n))).preorder]).rank()
print([a(n) for n in range(1, 26)])
CROSSREFS
KEYWORD
nonn,new
AUTHOR
Darío Clavijo, Jan 05 2025
STATUS
approved