Sorting Algorithm Quick Guide - SaasEasy Blog
Sorting AlgorithmAverage Time ComplexityWorst Case Time ComplexitySpace ComplexityStabilityDescription
Bubble SortO(n^2)O(n^2)O(1)StableSimple and easy to implement. Used on small data sets or as a simple teaching tool.
Selection SortO(n^2)O(n^2)O(1)UnstableSimple and easy to implement. Used on small data sets or as a simple teaching tool.
Insertion SortO(n^2)O(n^2)O(1)StableSimple and efficient for small data sets or partially sorted data.
Merge SortO(n log n)O(n log n)O(n)StableEfficient for sorting large amounts of data. Used in external sorting and in parallel computing.
Quick SortO(n log n)O(n^2)O(log n)UnstableEfficient for sorting large amounts of data. Used in practice for its average case performance, but can have poor worst-case performance.
Heap SortO(n log n)O(n log n)O(1)UnstableEfficient for sorting large amounts of data. Used in practice when the size of the data set is unknown or unbounded.
Radix SortO(dn)O(dn)O(n + k)StableEfficient for sorting data with a fixed number of digits or keys. Used in practice for sorting strings, integers, or IP addresses.
Counting SortO(n + k)O(n + k)O(n + k)StableEfficient for sorting integers with a small range. Used in practice for sorting grades, exam scores, and frequencies.
Bucket SortO(n + k)O(n^2)O(n + k)StableEfficient for sorting data with a uniform distribution. Used in practice for sorting letters, names, and ranges.
Shell SortO(n log n)Depends on gap sequenceO(1)UnstableEfficient for sorting data with a large number of elements. Used in practice for sorting word lists and arrays.
Comb SortDepends on gap sequenceO(n^2)O(1)UnstableEfficient for sorting data with a large number of elements. Used in practice for sorting word lists and arrays.
Cocktail SortO(n^2)O(n^2)O(1)StableVariation of bubble sort. Used in practice for sorting word lists and arrays.
Gnome SortO(n^2)O(n^2)O(1)StableEfficient for sorting small data sets. Used in practice for sorting word lists and arrays.
Pancake SortO(n^2)O(n^2)O(n)UnstableEfficient for sorting data with limited number of flips. Used in practice for sorting word lists and arrays.
Bogo SortO(n*n!)O(∞)O(1)UnstableInefficient and impractical for large data sets. Used as a benchmark for comparing other sorting algorithms.
Stooge SortO(n^2.71)O(n^?)O(n)UnstableRecursively sorts a quarter of the array pass by swapping with another quarter. Used in practice for sorting large and small arrays.
Batcher SortO(n log^2 n)O(n log^2 n)O(n)UnstableBased on mergesort. Used to sort large and small arrays.
Odd-even SortO(n^2)O(n^2)O(1)StableSimilar to bubble sort. Used for sorting small arrays.
Bitonic SortO(n log^2 n)O(n log^2 n)O(n log n)UnstableBased on mergesort. Used for data with a power of two size.
Cycle SortO(n^2)O(n^2)O(1)StableEfficient for sorting data with repeated elements. Used in practice for sorting words lists and arrays.
Pigeonhole SortO(n + k)O(n + k)O(n + k)StableEfficient for sorting data with integer keys within a small range. Used in practice for sorting ages, birthdates, phone numbers, and colors.
Library SortO(n log n)O(n log n)O(n log n)StableBased on radix sort. Used for sorting data with variable-length keys.
Binary Tree SortO(n log n)O(n^2)O(n)StableBuilds a binary search tree. Used in practice for sorting large and small data sets.
Bead SortO(n)O(n^2)O(n)UnstableEfficient for sorting non-negative integers with a small range. Used in practice for sorting trinkets, jewelry, and toys.
Smooth SortO(n log n)O(n log n)O(1)UnstableCombines heap sort with Fibonacci heaps. Used in practice for sorting data sets with a skewed distribution.
TimsortO(n log n)O(n log n)O(n)StableCombines insertion sort and merge sort. Used in practice for sorting arrays, lists, and stable sorts.
Cube SortO(n log n)O(n log n)O(n log n)UnstableEfficient for sorting numeric data. Used in practice for sorting scientific data.
Sleep SortO(n)O(n)O(1)UnstableSorts integers in time proportional to the largest number. Used in practice for fun purposes.
IntrosortO(n log n)O(n log n)O(log n)UnstableBased on quick sort with additional steps. Used in practice for sorting data that contains duplicates.
FlashsortO(n + k)O(n^2)O(k)UnstableEfficient for sorting data with a uniform distribution. Used in practice for sorting data from physical measurements.
The Different Types Of Algorithms
Data Structures & Algorithms

The Different Types Of Algorithms

Algorithms are an integral part of computer science and software development. They are step-by-step procedures for solving problems and are used in various applications such as data processing, artificial intelligence, and cryptography. Different types of algorithms are used to solve specific types of problems. In this article, we will explore the different types of algorithms […]

How To Write Quicksort: In Typescript
Data Structures & Algorithms

How To Write Quicksort: In Typescript

Introduction: When we talk about sorting algorithms, Quick Sort is one of the most widely used ones. It is a fast, efficient, and in-place algorithm. Typescript on the other hand, is a superset of Javascript which adds static typing, class-based object-oriented programming, and improved syntax to the language. It has gained popularity among developers due […]

How To Write Bubble Sort: In Typescript
Data Structures & Algorithms

How To Write Bubble Sort: In Typescript

Introduction Bubble sort is a popular sorting algorithm that is commonly used in computer science, and has been around for many years. The algorithm sorts an array of elements by continuously swapping neighboring elements until the array is sorted. In this article, we will be discussing how to implement bubble sort in Typescript, which is […]