Node-Sort-Algorithms
A sorting library for Node.js & javascript made based on well kown algorithmes included : Bead Sort , Gravity Sort , Bucket Sort , Bin Sort , Counting Sort , Insertion Sort , Merge Sort , Radix Sort
Sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonicalizing data and for producing human-readable output. More formally, the output must satisfy two conditions:
The output is in nondecreasing order (each element is no smaller than the previous element according to the desired total order); The output is a permutation (reordering) of the input.
Sorting Algorithm !
Class Sorting Algorithm
Data structure Array
**Comparison sorts*
Insertion Sort
Tim Sort
Merge Sort
Merge Sort 3 Way
Quick Sort
Quick Sort 3 Way
Selection Sort
Shell Sort
Bubble Sort
Bubble Sort Optimized
Cocktail Sort
Heap Sort
**Non-comparison sorts**
Bead Sort
Gravity Sort
Bucket Sort
Bin Sort
Counting Sort
Radix Sort
TODO .............................................
**Comparison sorts**
Intro Sort
Cube Sort
In-place merge Sort
Binary tree Sort
Cycle Sort
Library Sort
Patience Sorting
Smooth Sort
Strand Sort
Tournament Sort
Comb Sort
Gnome Sort
UnShuffle Sort[10]
Franceschini method Sort
Block Sort
Odd-Even Sort
**Non-comparison sorts**
Pigeonhole Sort
Bucket Sort(uniform keys)
Bucket Sort(integer keys)
LSD Radix Sort
MSD Radix Sort
MSD Radix Sort(in-place)
Spread Sort
Burst Sort
Flash Sort
Postman Sort
Note: the output must satisfy two conditions:
The output is in nondecreasing order (each element is no smaller
than the previous element according to the desired total order);
The output is a permutation (reordering) of the input.
Author: Amir Hatami
Installation
Install using the node.js package manager npm:
$ npm install node-sort-algorithms
Install via git clone:
$ git clone https://github.com/amhatami/Node-Sort-Algorithms node-sort-algorithms
$ cd node-sort-algorithms
$ npm install
Using directly via a browser, You can download node-sort-algorithms.js from GitHub or just bellow hotlink to it:
<script src="https://raw.githubusercontent.com/amhatami/Node-Sort-Algorithms/master/node-sort-algorithms.js"></script>
Requirements
You can install node-sort and its dependencies with npm:
$ npm install node-sort-algorithms
Dependencies
- Node.js v0.6+
Usage :
var nodesort = ;var displaymode = "No"; //"Yes"; // "Yes" for more details of algorithm progress ...;
Ruls :
- Depended on the Sort algorithms, input Array could be integers, float, decima, ocat, hex or binary.
- Array's element could be negative for only these Algorithms; Insertion Sort , Merge Sort , 3 Way Merge Sort , Quick Sort , 3 Way Quick Sort and etc.
- Returns error mesage if not found valid input.
- Turn On details of Algorithms progress useing : displaymode = "Yes"
var displaymode = "No"; //"Yes";
Example
Demos of the node-sort module are located in: ./test-Cases
var nodesort = ;var displaymode = "No"; //"Yes"; // "Yes" for more details of algorithm progress var base = 2;var RUN = 32; var arrin00 = 20 8 -11 12 22 9 10 ;var arrin01 = 20 8 48 120 220 390 1000 ;var arrin02 = 20 8 480 120 220 390 1000 ;var arrin03 = 1120 800 480 120 20 390 1000 ;var arrin04 = 'g' 'e' 'e' 'k' 's' 'f' 'o' 'r' 'g' 'e' 'e' 'k' 's';var arrin05 = 1 3 7 25 12 9 8 121 221 10 18 29 49;var arrin06 = 1 3 -7 25 12 9 8 121 221 -10 18 29 49;var arrin07 = 1 3 7000000000000000000 25 12 9 8 121 221 100000000000000000000000000 18 290000000000000000000 49;var arrin08 = 1 3 75432 25 12 9 8 121 221 976562 18 299999 49;var arrin09 = 0897 0565 0656 01234 0665 03434 0611 0621 ;var arrin10 = 1342 14293 0897 0565 0656 01234 0665 03434 0611 0621 ;var arrin11 = 5 8 11 12 2 9 10 4 11 10 12 7 9 ;var arrin12 = "";//var arrin13 = [A7,02,22,77,37,15,00,40,B00,75,04,05,07,75,52,12,50,77,71,D07]; //base16var arrin14 = 10011010101110011111001000111001011010110001001111011111110000011011111010; //base 2var arrin15 = 72227737151077074070750451077552125017771207; //base 8var arrin16 = 72315191210481100750001769121131820; // smal numbers for bead sortvar arrin17 = 45 -2 -45 78 30 -42 10 19 73 93;var arrin18 = 12 34 54 2 3;var arrin19 = 7231519121048110075000176912113182058111512291041110127915; // smal numbers for bead sort { var arr_original = inputArray ; var sortedArray = inputArray; ; return sortedArray;}; ;;;;;; //;;;;;;;;;;;;;;; ;
API Documentation
Parameters
- array - array to be sorted
- displaymode - for more details of algorithm progress
- base - for positional numeral system with a radix, or base e.g.(2 Binary - 8 Octal - 10 Decimal - 16 Hexadecimal - 60 Sexagesimal etc. ) List of numeral systems
Functions
**Comparison sorts**
-
Insertion Sort - .insertionSort( array )
-
Merge Sort - .mergeSort( array )
-
Merge Sort 3 Way - .mergeSort3Way( array )
-
Quick Sort - .quickSort( array )
-
Quick Sort 3 Way - .quickSort3Way( array )
-
Tim Sort - .timSort( array )
-
Selection Sort - .selectionSort( array )
-
Shell Sort - .shellSort( array )
-
Bubble Sort - .bubbleSort( array )
-
Bubble Sort Optimized - .bubbleSortOptimized( array )
-
Cocktail Sort - .cocktailSort( array )
-
Heap Sort - .heapSort( array )
**Non-comparison sorts**
-
Radix Sort - .radixSort( array , base )
-
Counting Sort - .countingSort( array )
-
Bucket Sort (integer keys) - .bucketSort( array )
-
Bin Sort - .binSort( array )
-
Bead Sort - .beadSort( array )
-
Gravity Sort - .gravitySort( array )
Coming soon :) !
-
Intro Sort - .introSort( array )
-
Cube Sort - .cubeSort( array, [comparator] )
TODO ............................................. Comparison sorts Intro Sort
Cube Sort Shell Sort In-place merge Sort Binary tree Sort Cycle Sort Library Sort Patience Sorting Smooth Sort Strand Sort Tournament Sort Comb Sort Gnome Sort UnShuffle Sort[10] Franceschini method Sort Block Sort Odd-Even Sort
Non-comparison sorts
Pigeonhole Sort Bucket Sort(uniform keys) LSD Radix Sort MSD Radix Sort MSD Radix Sort(in-place) Spread Sort Burst Sort Flash Sort Postman Sort
Testing
Issue the following node command in the same directory to run the UnitTest.js test cases:
$ node UnitTest
LICENSE
node-sort-algorithms: Copyright (c) 2016 Amir Hatami
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Refrences
- https://en.wikipedia.org/wiki/Sorting_algorithm
- http://algs4.cs.princeton.edu/20sorting/
- https://www.toptal.com/developers/sorting-algorithms
- http://www.geeksforgeeks.org/sorting-algorithms/
- https://www.hackerrank.com/domains/algorithms/arrays-and-sorting
- https://leetcode.com/problemset/algorithms/
- https://www.topcoder.com/community/data-science/data-science-tutorials/sorting/