Generating all rooted trees

Matlab code to enumerate all possible trees on n nodes: I wrote this awhile ago when I needed to enumerate all possible trees that could be formed by a set of n nodes. There are n^(n-1) such trees. This code uses the fact that there is a bijection between these trees and Prufer sequences. Here is tree_enumeration.m, which is a skeleton file for running code on all possible trees, and here is the function for generating the next tree, get_next_tree.m.

Speak Your Mind