Constructing resulting tree for two input trees.