Best sorting algorithms on Javascript arrays.
API docs published here.
var algojs = require('algojs-sorting');
var arr = [88,24,33,2,12,9];
algojs.quickSort(arr);
// --> arr is sorted!
in place? | stable | worse | average | best | |
---|---|---|---|---|---|
selectionSort | x | N^2 / 2 | N^2 / 2 | N^2 / 2 | |
insertionSort | x | x | N^2 / 2 | N^2 / 4 | N |
shellSort | x | ? | ? | N | |
mergeSort | x | N * logN | N * logN | N * logN |
Array is sorted as side effect in average quadratic time. See selection sort.
algojs.selectionSort(arr);
Array is sorted as side effect in average quadratic time (but linear in best case). See insertion sort.
algojs.insertionSort(arr);
Array is sorted as side effect in unknown average time (but linear in best case). See shell sort
algojs.shellSort(arr);
Array is sorted as side effect in linearithmic time. See merge sort
algojs.shellSort(arr);