Algorithms class was a such a long time ago and I can't remember the name of the algorithm to balance an acyclic graph.
Let's start with a graph that looks like this:
1 | 2 | 3 / \ 4 7 / \ | 5 6 8 The solution to balancing this out would be:
2 3 / \ / | \ 1 3 2 4 7 / \ => / / \ | 4 7 1 5 6 8 / \ | 5 6 8 You rotate until the you have a root node whose branch's are the same length and your tree is at a minimum height.
What algorithm am I describing?