@*Intro. On 07 June 2024, Jim Propp told me about an interesting bijective mapping on (ordered) trees that have more than node: ``The rightmost child of the old root becomes the new root, and the old root becomes its leftmost child.'' (If the old children are $c_1,ドル \dots, $c_k,ドル the new children are the children of $c_k$ preceded by a subtree whose children are $c_1,ドル \dots, $c_{k-1}$.) This mapping preserves the order of leaves. The main point is that {\sl every node previously on an even level is now on an odd level, and vice versa.} While playing with this transformation, I noticed that the number of trees that have $m$ nodes on odd levels and $n$ nodes on even levels, for $m,n>0,ドル is the Narayana number $$T(m,n)={(m+n-1)!,円(m+n-2)!\over m!,円(m-1)!,円n!,円(n-1)!},$$ which is well known to be the number of binary trees that have $m$ null left links and $n$ null right links. (The tree has $m+n$ nodes; the binary tree has $m+n-1$ nodes, $n-1$ nonnull left links, and $m-1$ nonnull right links. See, for example, exercise 2.3.4.6--3 in {\sl The Art of Computer Programming}.) So I looked for a bijection between such trees and such binary trees. This program implements the bijection that I came up with. In a sense, it's a sequel to my ``Three Catalan bijections,'' {\sl Institut Mittag-Leffler Reports}, No.~04, 2004/2005, Spring (2005), 19~pp. Unfortunately, I don't have time to provide extensive comments. Let the code speak for itself. @d nodes 17 /* nodes in the tree; must be at least 2 */ @d vbose 0 /* set this nonzero to see details */ @c #include int llink[nodes+1],rlink[nodes]; /* links of the binary tree */ int lchild[nodes+1],rsib[nodes+1]; /* leftmost child and right sibling in the tree */ int count[nodes]; @; main() { register j,k,y; printf("Checking all trees with %d nodes...\n", nodes); @; while (1) { @; if (vbose) @; @; @; } for (k=1;count[k];k++) printf("Altogether %d case%s with %d node%s at odd levels.\n", count[k],count[k]==1?"":"s",k,k==1?"":"s"); } @ @= { print_binary_tree(); printf(" -> "); print_tree(); printf("\n"); } @ @d encode(x) ((x)<10? '0'+(x): 'a'+(x)-10) @= void print_binary_tree(void) { register int k; for (k=1;k= for (k=1;k= for (j=1;!llink[j];j++) rlink[j]=0, llink[j]=j+1; if (j==nodes) break; for (k=0,y=llink[j];rlink[y];k=y,y=rlink[y]) ; if (k) rlink[k]=0;@+else llink[j]=0; rlink[y]=rlink[j], rlink[j]=y; @ The bijection is implemented by a recursive procedure, which has three parameters: |p| is the index of the first node not already created; |r| is the root of the binary tree to be converted to a tree; |parity| is 1 if we are interchanging |llink| with |rlink|. This procedure returns the index of the root node of the constructed tree. @= int propp(int p,int r,int parity) { register lam,rho; if (r==0) { lchild[p]=rsib[p]=0; return p; } if (parity==0) { lam=propp(p,llink[r],1); rho=propp(lam+1,rlink[r],0); }@+else { lam=propp(p,rlink[r],0); rho=propp(lam+1,llink[r],1); } rsib[lam]=lchild[rho], lchild[rho]=lam; return rho; /* note that |rsib[rho]=0| */ } @ @= if (propp(1,1,0)!=nodes) fprintf(stderr,"I'm confused!\n"); @ The |lcount| routine determines how many nodes of a given nonempty tree, rooted at |r|, are at a level with a given parity. (The root is at level zero.) @= int lcount(int r,int parity) { register int c,p; for (c=1-parity,p=lchild[r];p;p=rsib[p]) c+=lcount(p,1-parity); return c; } @ @= for (j=0,k=1;k; } count[j]++; @*Index.

AltStyle によって変換されたページ (->オリジナル) /