Skip to main content

Bubble Sort

Pass the array of numbers which needs to be sorted.

Usage

src/sample/bubblesort.ts
import { bubbleSort } from 'athro';

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

const result = bubbleSort(arr)

Time Complexity

The time complexity of Bubble Sort is:

CaseTime ComplexityDescription
BestO(n)When the data is already sorted upto some extent
AverageO(n2)n comparisons for n items
WorstO(n2)n comparisons for n items