min_tree function