Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate through all trees of a given size

I am often faced with the problem of checking some property of trees (the graph ones) of a given size by brute force. Do you have any nice tricks for doing this? Ideally, I'd like to examine each isomorphism class only once (but after all, speed is all that matters).

Bit twiddling tricks are most welcome since n is usually less than 32 :)

I'm asking for slightly more refined algorithms than the likes of "loop through all (n-1)-edge subsets and check if they form a tree" for trees on n nodes.

like image 730
Erik Avatar asked Dec 08 '25 12:12

Erik


1 Answers

This is in Knuth's The Art of Computer Programming volume on Combinatorial Algorithms. If I remember correctly, it's an exercise there. Since he has the solutions for such, I point you there.

like image 91
jason Avatar answered Dec 11 '25 15:12

jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!