< script src="/app.js" defer>
Posts Sorting in capsule
Post
Cancel

Sorting in capsule

This blog is a snapshot of all well known sorting algorithms and its attributes.

AlgorithmTime complexitySpace complexityAttributes
Best caseAverage caseWorst case
Insertion SortO(n)O(n²)O(n²)O(1)Stable, In-Place, Comparison based, used as base case for hybrid sort (timsort)
Selection SortO(n²)O(n²)O(n²)O(1)Not Stable, In-Place, Comparison based, used in heavy memory write use cases , used in small dataset
Bubble SortO(n)O(n²)O(n²)O(1)Stable, In-Place, Comparison based
Merge SortO(n log n)O(n log n)O(n log n)O(n)Stable, Not In-Place, Comparison based, large dataset, external sorting (files, directories)
Quick SortO(n log n)O(n log n)O(n²)O(log n) (average)
O(n) (worst)
Not Stable, In-Place, Comparison based, general purpose
Heap SortO(n log n)O(n log n)O(n log n)O(1)Not Stable, In-Place, Comparison based, when guaranteed to be O(n log n) and constant space requirement
Counting SortO(n + k)O(n + k)O(n + k)O(n + k)Stable, Not In-Place, Not Comparison based, Integer with small know range (score, age)
Bucket SortO(n + k)O(n + k)O(n²)O(n + k)Depends on hash function(Stable or not), Not In-Place, Not Comparison based, Uniformly distributed floating point numbers
Radix SortO(d · (n + k))O(d · (n + k))O(d · (n + k))O(n + k)Stable, Not In-Place, Not Comparison based, Integer with small know range (id, phone number)
This post is licensed under CC BY 4.0 by the author.