SelectionSort

From allmyalgorithms
Jump to: navigation, search

Selection sort repeatedly selects the smallest element from the input sequence, deletes it, and adds it to the end of the output sequence. It has a worst-case time complexity of \mathcal{O}(n^2).

Synonyms are Sort by Selection

array selectionSort(array input) {
  array output;
  while (!input.empty()) {
    (minValue, minIndex) = min(input);
    input.remove(minIndex);
    output.append(minValue);
  }
  return output;
}
Personal tools
Namespaces

Variants
Actions
Categories
Wiki navigation
Toolbox