https://github.com/ibrahimtanyalcin/mergesort
Merge Sort algorithm implementation without recursion, using cached binary trees
https://github.com/ibrahimtanyalcin/mergesort
javascript merge-sort mergesort mergesort-algorithm performance sorting-algorithms stable-sort
Last synced: about 2 months ago
JSON representation
Merge Sort algorithm implementation without recursion, using cached binary trees
- Host: GitHub
- URL: https://github.com/ibrahimtanyalcin/mergesort
- Owner: IbrahimTanyalcin
- License: mit
- Created: 2021-08-05T14:23:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-10T11:58:01.000Z (over 4 years ago)
- Last Synced: 2025-01-24T06:27:21.517Z (11 months ago)
- Topics: javascript, merge-sort, mergesort, mergesort-algorithm, performance, sorting-algorithms, stable-sort
- Language: JavaScript
- Homepage:
- Size: 556 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MergeSort
[](https://www.codacy.com/gh/IbrahimTanyalcin/MergeSort/dashboard?utm_source=github.com&utm_medium=referral&utm_content=IbrahimTanyalcin/MergeSort&utm_campaign=Badge_Grade)
[](https://zenodo.org/badge/latestdoi/393070702)
Mergesort algorithm without recursion, using cached binary trees 👇
- Generating a tree beforehand, divides the problem in half, where the first part can be calculated once and reused for arrays with same size.
- Lack of recursion avoids functions calls, making the algorithm perform as close as possible to natively compiled vendor implementations.
For larger arrays (> 1M) it performs faster than native solutions (around %25-%50 faster). For smaller arrays performs comparable or slower (around %25 slower).
|milliseconds| 1M *| 10M **†| 100K †| 100K |
|:----:|:----:|:----:|:-----:|:-----:|
|Mergesort| 34900| 229000| 11000 |10900
|Chrome| 35200| 326000|10200 |10200
†: Instance created using `size` option
*: 50 iterations
**: 30 iterations
## [Documentation](https://ibrahimtanyalcin.github.io/MergeSort/)
For a list of config options, see [here](https://ibrahimtanyalcin.github.io/MergeSort/).
For directly embedding to html, if you are using a browser with compatibility > ie11, use the file ending with `...evergreen.min.js` in the `dist` folder. Otherwise, you can fall back to `...es5.min.js`. To read the entire build, refer to the files without the `.min.` part.
## Usage
```javascript
let instance = Mergesort(),
array = Array.from({length:100}).map(d => Math.random());
instance(array, (a,b) => a - b);
```
## Installation
```javascript
npm install @ibowankenobi/mergesort
```
## Build
```javascript
npm run build
```
You will end up with 4 files in the `dist` folder, an es5 version, an es6 version and minified versions of both.
## Browser
```javascript
```
The contents of the request above is the same as `./dist/mergesort.x.y.z.evergreen.min.js`.
If you want to request a particular version, check instructions at [jsdelivr](https://www.jsdelivr.com/).