public static int[] selectLast(
      double[] S, int[] freq, int k, SelectionAlgorithm selectionAlgorithm) {
    int[] results = new int[k];
    if (k > 0) {
      int size = freq == null ? S.length : accumulate(freq, 0, freq.length);