Optimal construction of k-nearest neighbor graphs for identifying noisy clusters