# Classification of Sorting Algorithms

• Difficulty Level : Medium
• Last Updated : 23 Nov, 2021

Sorting is an algorithm which arranges the elements of a given list in a particular order [ascending or descending].

Sorting algorithms are categorized on the following basis –

1. By number of comparisons :
Comparison-based sorting algorithms check the elements of the list by key comparison operation and need at least O(n  log n) comparisons for most inputs. In this method, algorithms are classified based on the number of comparisons. For comparison based sorting algorithms, best case behavior is O(n log n) and worst case behavior is O(n2). For example – Quick Sort, Bubble Sort ,Insertion Sort etc.

2. By Number of Swaps :
In this method, sorting algorithms are categorized by the number of swaps (interchanging of position of to numbers, also called inversion).

3. By Memory Usage :
Some sorting algorithms are “in place” and they need O(1) or O(log n) memory to create auxiliary locations for sorting the data temporarily.

4. By Recursion :
Sorting algorithms are either recursive (for example – quick sort) or non-recursive (for example – selection sort, and insertion sort), and there are some algorithms which use both (for example – merge sort).

5. By Stability :
Sorting algorithm is stable if two elements with equal values appear in the same order in output as it was in the input. The stability of a sorting algorithm can be checked with how it treats equal elements. Stable algorithms preserve the relative order of equal elements, while unstable sorting algorithms don’t. In other words, stable sorting maintains the position of two equals elements similar to one another. For example – Insertion Sort, Bubble Sort , and Radix Sort.