Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Increasing permutation trees

For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left and right children there isn't a distinction between them and mirroring the tree or a sub-tree does not produce a new tree.

In this challenge you will be given an integer \$n\$ and you will be asked to determine the number of binary trees with each node labeled from \1ドル\$ to \2ドルn+1\$ such that no child node is less than its parent.

For example the following tree with 7 nodes is valid:

 1
 2 7
3 4
 5 6

but the following tree is not:

 1
 2 7
6 4
 5 3

Since 3 is a child of 4.

Task

Given \$n\$ calculate the number of binary trees labeled from \1ドル\$ to \2ドルn+1\$ such that no child node is less than its parent.

This is so the goal is to minimize the size of your source code as measured in bytes.

Test cases

I've calculated the first 11 solutions on my own:

1, 1, 4, 34, 496, 11056, 349504, 14873104, 819786496, 56814228736, 4835447317504

and the OEIS has more terms at: A002105

Answer*

Draft saved
Draft discarded
Cancel
3
  • \$\begingroup\$ for _ in range(n+n-2) -> for _ in"_"*~-n*2 for 81 bytes: Try it online! \$\endgroup\$ Commented Jun 4, 2022 at 19:32
  • 3
    \$\begingroup\$ @pxeger Even I know a golfier way of saying "_"*2... \$\endgroup\$ Commented Jun 4, 2022 at 21:45
  • \$\begingroup\$ Heh, good point. \$\endgroup\$ Commented Jun 5, 2022 at 6:04

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