An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# MergeSort
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/b623fd94de934c0897bf646814d3476f)](https://www.codacy.com/gh/IbrahimTanyalcin/MergeSort/dashboard?utm_source=github.com&utm_medium=referral&utm_content=IbrahimTanyalcin/MergeSort&utm_campaign=Badge_Grade)
[![DOI](https://zenodo.org/badge/393070702.svg)](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/).