How can I randomly generate trees?

380 Views Asked by At

I want to randomly generate trees, i.e. undirected acyclic graphs with a single root, making sure that all possible trees with a fixed number of nodes n are equally likely.

1

There are 1 best solutions below

4
On

Knuth says to look at it as generating all nested parentheses in lexicographic order.

Look here for the details

http://www-cs-faculty.stanford.edu/~uno/fasc4a.ps.