/js-mergesorts

Various flavors of Merge-Sort in JavaScript

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

MergeSorts in JavaScript

Various Merge Sort implimentations in pure javascript.

Details

The above files use different approaches to perform a merge sort.

1. mergesort-recursive-concat.js

  • Splits the input, uses recursive concatination and then sorts
  • Does not store in extra Arrays
  • Moderate space complexity
  • Moderate - High computational complexity

2. mergesort-indexed.js

  • Uses index rather than splitting the array
  • Progressive with no returns (Modifies the input array itself)
  • Very Low space complexity (Less Memory)
  • Moderate computational complexity

3. mergesort-3-arrays.js

  • Simple
  • Uses 3 Arrays - Left Sub-Array, Right Sub-Array, Merged
  • High space complexity (Uses more memory)
  • Very Low computational complexity (Good performance)

Usage

When using mergesort-recursive-concat.js or mergesort-3-arrays.js

 var sortedArray = mergeSort(unsortedArray); 

When using mergesort-indexed.js, the input array would be modified

 mergeSort(unsortedArray); 

Licence

Licenced under GNU GENERAL PUBLIC LICENSE v3.0. It is free to copy, use and distribute.