def METHOD_NAME(self, algorithm, metric):
    # given the algorithm string + metric string, choose the optimal
    # algorithm to compute the result.
    if algorithm == 'auto':
        # use KD Tree if possible
        if metric in KDTree.valid_metrics:
            return 'kd_tree'
        elif metric in BallTree.valid_metrics:
            return 'ball_tree'
        else:
            raise ValueError("invalid metric: '{0}'".format(metric))
    elif algorithm in TREE_DICT:
        if metric not in TREE_DICT[algorithm].valid_metrics:
            raise ValueError("invalid metric for {0}: "
                             "'{1}'".format(TREE_DICT[algorithm],
                                            metric))
        return algorithm
    else:
        raise ValueError("invalid algorithm: '{0}'".format(algorithm))