Skip to main content

Merge Sort

Pass the array of numbers which needs to be sorted.

Usage

src/sample/mergesort.ts
import { mergeSort } from 'athro';

const arr = [2, 6, 3, 8];

const result = mergeSort(arr)

Time Complexity

The time complexity of Merge Sort is:

CaseTime ComplexityDescription
BestO(nlogn)O(logn) decompositions and O(n) comparisons per decomposition
AverageO(nlogn)O(logn) decompositions and O(n) comparisons per decomposition
WorstO(nlogn)O(logn) decompositions and O(n) comparisons per decomposition