Skip to content

Instantly share code, notes, and snippets.

@alaingoldman
Created February 11, 2019 14:33
Show Gist options
  • Save alaingoldman/c91af0e0075b9538792415a7265195ed to your computer and use it in GitHub Desktop.
Save alaingoldman/c91af0e0075b9538792415a7265195ed to your computer and use it in GitHub Desktop.
var a = ["S", "O", "R", "T", "E", "X", "A", "M", "P", "L", "E"];
for (let i = 0; i < a.length; i++) {
let f = i;
let low = f;
while (f < a.length) {
if (a[f] > a[low]) {
low = f;
}
f++;
}
let tempValue = a[low];
a.splice(low, 1);
a.unshift(tempValue);
}
console.log(a);
// Proposition A.
// Selection sort uses N^2/2 compares and N exchanges to sort an array of length N.
// runtime of this on an array that is fully in order is the same as an array that is fully out of order!
// this is because of the N exchanges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment