
Last chance! 50% off unlimited learning
Sale ends in
sample_tree
generates a random with a given number of nodes uniform
at random from the set of labelled trees.
sample_tree(n, directed = FALSE, method = c("lerw", "prufer"))
A graph object.
The number of nodes in the tree
Whether to create a directed tree. The edges of the tree are oriented away from the root.
The algorithm to use to generate the tree. ‘prufer’ samples Prufer sequences uniformly and then converts the sampled sequence to a tree. ‘lerw’ performs a loop-erased random walk on the complete graph to uniformly sampleits spanning trees. (This is also known as Wilson's algorithm). The default is ‘lerw’. Note that the method based on Prufer sequences does not support directed trees at the moment.
In other words, the function generates each possible labelled tree with the given number of nodes with the same probability.
g <- sample_tree(100, method="lerw")
Run the code above in your browser using DataLab