So in the last post about listing trees I outlined a slightly cumbersome method to list trees from degree sequences. Thinking about it a bit more, it would probably be far easier to just list all trees on some number of vertices and filter out by degree sequence. I talked a little about the WROM algorithm in this old post which is a constant time generator of 'free' (unlabelled) trees.
Anyway, that's boring so I was trying out the more complicated approach. It looks like generating a single tree from a degree sequence is as simple as the Havel-Hakimi method. Connect the largest degree (dn) to the dn next largest degrees. Also maintain a list of vertices that have already been connected to, and then at the next step connect only to those not already connected to. So, for [3, 3, 2, 1, 1, 1, 1] we get:
You might notice that trees a) and c) are isomorphic. Below the trees labelled by degree are the same trees labelled by DFS discovery order, and below that the 'layout' of the tree as described in the WROM paper.
As it happens, I tried to use restricted weak compositions and what I call 'labelled partitions' to do this efficiently but it doesn't work so well yet. It seems like this could all be done far easier using just successor functions...
Anyway, that's boring so I was trying out the more complicated approach. It looks like generating a single tree from a degree sequence is as simple as the Havel-Hakimi method. Connect the largest degree (dn) to the dn next largest degrees. Also maintain a list of vertices that have already been connected to, and then at the next step connect only to those not already connected to. So, for [3, 3, 2, 1, 1, 1, 1] we get:
You might notice that trees a) and c) are isomorphic. Below the trees labelled by degree are the same trees labelled by DFS discovery order, and below that the 'layout' of the tree as described in the WROM paper.
As it happens, I tried to use restricted weak compositions and what I call 'labelled partitions' to do this efficiently but it doesn't work so well yet. It seems like this could all be done far easier using just successor functions...
Comments