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)).
LINKS
Rosetta code, Permutations/Rank of a permutation.
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