Optimised tree creation by ordering nodes by weight