Sorting Algorithms
Last Updated : 20 Jan, 2026
A Sorting Algorithm is used to rearrange a given array or list of elements
in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10,
20] after sorting in increasing order and becomes [20, 10, 5, 2] after
sorting in decreasing order.
There exist different sorting algorithms for different different types
of inputs, for example a binary array, a character array, an array
with a large range of values or an array with many duplicates or a
small vs large array.
The algorithms may also differ according to output requirements.
For example, stable sorting (or maintains original order of equal
elements) or not stable.
Sorting is provided in library implementation of most of the
programming languages. These sorting functions typically are
general purpose functions with flexibility of providing the expected
sorting order (increasing or decreasing or by a specific key in case of
objects).
Basics
Introduction to Sorting
Applications of Sorting
Sorting Algorithms:
Comparison Based : Selection Sort, Bubble Sort, Insertion Sort, Merge
Sort, Quick Sort, Heap Sort, Cycle Sort, 3-way Merge Sort
Non Comparison Based : Counting Sort, Radix Sort, Bucket
Sort, Pigeonhole Sort
Hybrid Sorting Algorithms : IntroSort, TimSort
Library Implementations:
qsort() in C
sort() in C++ STL
[Link]() in Java with examples
[Link]() in Java with Examples
Sort a List in Python
Sorting in JavaScript
Easy Problems
Check if Sorted
Sort an array of two types
Sort a String
Sort a Matrix
Sort a Linked List
Sort in Wave Form
Sort from Different Machines
Check if any two intervals overlap
Missing elements of a range
Sort by set bits counts
Sort even and odd placed in different orders
Sort strings by lengths
Merge Two Sorted
Sort when two halves are sorted
2 Sum - Pair in a Sorted Array
Intersection & Union of two Sorted
Meeting Rooms
K-th smallest after removing given Set
Medium Problems
Sort by Frequency
Minimum Increments to Make Unique
Merge Overlapping Intervals
Maximum intervals overlap
Minimum Platforms
Chocolate Distribution Problem
Min and Max Amount to Buy All
Three Way Partitioning
Sort an array of 0s, 1s and 2s