algojs-sorting
v0.3.0
Published
Best sorting algorithms on Javascript arrays.
Downloads
5
Readme
algojs-sorting
Best sorting algorithms on Javascript arrays.
API docs
API docs published here.
var algojs = require('algojs-sorting');
var arr = [88,24,33,2,12,9];
algojs.quickSort(arr);
// --> arr is sorted!
Algorithms
| | 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 |
Selection Sort
Array is sorted as side effect in average quadratic time. See selection sort.
algojs.selectionSort(arr);
Insertion Sort
Array is sorted as side effect in average quadratic time (but linear in best case). See insertion sort.
algojs.insertionSort(arr);
Shell Sort
Array is sorted as side effect in unknown average time (but linear in best case). See shell sort
algojs.shellSort(arr);
Merge Sort
Array is sorted as side effect in linearithmic time. See merge sort
algojs.shellSort(arr);