Created
February 11, 2019 14:33
-
-
Save alaingoldman/c91af0e0075b9538792415a7265195ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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