Skip to main content

Merge Sort

A divide-and-conquer algorithm that splits the array in half, sorts each half, and merges them back together.

Interactive Visualization

Loading visualization…

Usage

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

const arr = [2, 6, 3, 8];
const result = mergeSort(arr);

Time Complexity

CaseTime ComplexityDescription
BestO(n log n)Consistent divide-and-merge pattern
AverageO(n log n)Stable performance across inputs
WorstO(n log n)Same recursive structure