RandomTree

RandomTree[n]

gives a pseudorandom tree with n nodes.

RandomTree[n,k]

gives a list of k pseudorandom trees.

RandomTree[n,{k1,k2,}]

gives a k1× k2× array of trees.

Details and Options

  • RandomTree[n] samples from the discrete uniform distribution over the labeled, rooted, ordered trees of size n, where is given by CatalanNumber[n-1]. Any reordering of the data or subtrees represents a different tree. »
  • RandomTree gives a different sequence of pseudorandom trees whenever you run the Wolfram Language. By using SeedRandom, you can get a repeatable sequence. »
  • The data of the trees produced by RandomTree[n,] is taken to be integers 1, , n. »
  • RandomTree takes the same options as Tree.

Examples

open allclose all

Basic Examples  (3)

Generate a random tree with 10 nodes:

Generate a list of random trees:

Generate an array of random trees:

Options  (9)

Styling Individual Tree Elements  (2)

Specify the label for the generated tree element:

Specify labels and styles for subtrees by position:

Styling Entire Tree  (4)

Specify labels and styles for all subtrees:

Specify the base style:

Specify the styles for both the edges and the edges of the tree elements:

Specify the base style and styles for individual tree elements:

Tree Layout and Graphics Options  (3)

Specify the orientation for the root:

Specify a named embedding:

Specify Graphics options:

Applications  (1)

Create a random symbolic expression:

Properties & Relations  (6)

RandomTree uses integer data:

Use TreeMap to replace data in the tree:

RandomTree gives pseudorandom trees:

Use SeedRandom to get repeatable random trees:

Use BlockRandom to block one use of RandomTree from affecting others:

RandomTree[n] can produce n! CatalanNumber[n-1] different trees:

RandomTree[n] samples from the uniform distribution over the labeled, rooted, ordered trees of size n:

RandomTree generates random trees of a certain size:

NestTree can be used to generate random trees with random data and numbers of children:

Wolfram Research (2021), RandomTree, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTree.html (updated 2021).

Text

Wolfram Research (2021), RandomTree, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTree.html (updated 2021).

CMS

Wolfram Language. 2021. "RandomTree." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/RandomTree.html.

APA

Wolfram Language. (2021). RandomTree. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomTree.html

BibTeX

@misc{reference.wolfram_2023_randomtree, author="Wolfram Research", title="{RandomTree}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/RandomTree.html}", note=[Accessed: 29-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_randomtree, organization={Wolfram Research}, title={RandomTree}, year={2021}, url={https://reference.wolfram.com/language/ref/RandomTree.html}, note=[Accessed: 29-March-2024 ]}