Takes random tree structure and makes it balanced via find-center algorithm Center of tree is the node from which greatest way to all leaves is minimal, or center of diameter (greatest distance between nodes)
Center of tree could be found with 2 (or more, esp. as graph cases) algorithms:
Here we implement second one - by shrinking tree from leaf nodes
Example tree used in algorithm:
With this example tree algorithm finds node 10 as center BUT there are 2 centers, 6 and 10, and the next approach would be analysing subtree sizes if 2 centers found and claim final center the one of two which has "heavier" subtree.