2

There are n! permutations that can be inserted into an initially empty binary tree, but only Catalan(n) different binary trees. A possible method (surely very ineffective, but I'm an old FORTRAN guy, meaning that I automatically hate classes and recursion) to weed out duplicates would be the following: If a left child is filled in and already a right child is present, duplicate (break loop), since in an "earlier" permutation, you already filled the left first, with the same result.

My question: The mirror of a binary tree has the same "structural" properties and I can exclude it too. But is a simple mirror argument enough to conclude I can loop only through the first half of the permutations, i.e. it can't be that I "forget" a tree because all the reversed permutations have been weeded out as above? Example: 123,132,213,231,312,321. 231 gets deleted, and that is "safe" as it is in the second half anyway.

To make it a bit more formal: Let $P$ be a permutation sequence, $P'$ its number conjugate (replace all $i$ by $n+1-i$, e.g. 213 by 231). Call $P$ "bad" if there exist $i<j<k$ such that $P(k)<P(i)<P(j)$. Call $P$ "small" if $P<P'$ lexicographically. Let $M=P(T)$ be the set of all $P$ that generate the binary tree $T$. Can it be that for some $T$ all small $P$ in $M$ are bad?

Or even shorter, courtesy of Gribouillis: Let $P$ be stack-sortable, see below. Can $P'$ (with $P'<P$, alphanumerically) be not stack-sortable?

EDIT: The formal question is correct, the informal not, as $T(3,1,4,2)=T(3,1,2,4)$ but $2$ and $4$ don't hang on the same node.

EDIT2: Argl. See my comment below.

  • If I understand correctly, there are no small permutations that generate tree with left part empty (as the first element in permutation has to be $n$), so vacuously all small permutations for such tree are bad. – mihaild Feb 21 '24 at 11:27
  • Is your question related to stack-sortable permutations? https://en.wikipedia.org/wiki/Stack-sortable_permutation – Gribouillis Feb 21 '24 at 18:14
  • @Gribouillis: Bingo! This is indeed another way to describe it. (And I made another dumb goof, "reverse permutation" is nonsense, mirrored trees are number-conjugate - sorry mihaild!) – Hauke Reddmann Feb 22 '24 at 08:05
  • The first formal version - I think $M$ should be permutations that generate tree or its mirror? Otherwise still no small permutation generates tree with right side bigger than left. If it is so, then mirroring tree such that left side is at least as big as right, and listing it in preorder, gives you small not-bad permutation. For the second version - $(21)$ is stack-sortable, but it's not in the first half of all permutations. – mihaild Feb 22 '24 at 11:20
  • @mihaild: Son of Argl. Double negatives and me will never become friends. I hope this is my final edit...But I think your comment answered it anyway. – Hauke Reddmann Feb 23 '24 at 08:42
  • $P = (4213)$ is stack-sortable, but $P' = (1342)$ is not. – mihaild Feb 24 '24 at 12:56

0 Answers0