updated min_depth algorithm