Sorting Algorithms Read Discuss Courses Learn Data Structures and Algorithms | DSA Tutorial Learn more about Sorting in DSA Self Paced Course Practice Problems on Sorting Top Quizzes on Sorting Algorithms What is Sorting? A Sorting Algorithm is used to rearrange a given array or list of elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of elements in the respective data structure. For Example: The below list of characters is sorted in increasing order of their ASCII values. That is, the character with a lesser ASCII value will be placed first than the character with a higher ASCII value. Sorting Algorithms Sorting Algorithms: Selection Sort Bubble Sort Insertion Sort Merge Sort Quick Sort Heap Sort Counting Sort Radix Sort Bucket Sort Bingo Sort Algorithm ShellSort TimSort Comb Sort Pigeonhole Sort Cycle Sort Cocktail Sort Strand Sort Bitonic Sort Pancake sorting BogoSort or Permutation Sort Gnome Sort Sleep Sort – The King of Laziness Structure Sorting in C++ Stooge Sort Tag Sort (To get both sorted and original) Tree Sort Odd-Even Sort / Brick Sort 3-way Merge Sort Table of Complexity Comparison: Name Best Case Average Case Worst Case Memory Stable Method Used Quick Sort No Partitioning Merge Sort n Yes Merging Heap Sort 1 No Selection Insertion Sort n 1 Yes Insertion Tim Sort n n Yes Insertion & Merging Selection Sort 1 No Selection Shell Sort 1 No Insertion Bubble Sort n 1 Yes Exchanging Tree Sort n Yes Insertion Cycle Sort 1 No Selection Strand Sort n n Yes Selection Cocktail Shaker Sort n 1 Yes Exchanging Comb Sort 1 No Exchanging Gnome Sort n 1 Yes Exchanging Odd–even Sort n 1 Yes Exchanging Library Implementations: Introsort – C++’s Sorting Weapon Comparator function of qsort() in C sort() in C++ STL C qsort() vs C++ sort() Arrays.sort() in Java with examples Collections.sort() in Java with Examples Some standard problems on Sorting: Easy: Sort elements by frequency Sort an array of 0s, 1s and 2s Sort numbers stored on different machines Sort an array in wave form Check if any two intervals overlap among a given set of intervals How to sort an array of dates in C/C++? Sorting Strings using Bubble Sort Find missing elements of a range Sort an array according to count of set bits Sort even-placed elements in increasing and odd-placed in decreasing order Sort an array when two halves are sorted Sorting Big Integers Sort a linked list of 0s, 1s and 2s Medium: Inversion count in Array using Merge Sort Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted Sort a nearly sorted (or K sorted) array Sort n numbers in range from 0 to n^2 – 1 in linear time Sort an array according to the order defined by another array Find the point where maximum intervals overlap Find a permutation that causes worst case of Merge Sort Sort Vector of Pairs in ascending order in C++ Minimum swaps to make two arrays identical Chocolate Distribution Problem Permute two arrays such that sum of every pair is greater or equal to K Bucket Sort To Sort an Array with Negative Numbers Sort a Matrix in all way increasing order Convert an Array to reduced form using Vector of pairs Smallest Difference Triplet from Three arrays Check if it is possible to sort an array with conditional swapping of adjacent allowed Hard: Find Surpasser Count of each element in array Count distinct occurrences as a subsequence Count minimum number of subsets (or subsequences) with consecutive numbers Chose k array elements such that difference of maximum and minimum is minimized Minimum swap required to convert binary tree to binary search tree K-th smallest element after removing some integers from natural numbers Maximum difference between frequency of two elements such that element having greater frequency is also greater Minimum swaps to reach permuted array with at most 2 positions left swaps allowed Find whether it is possible to make array elements same using one external number Sort an array after applying the given equation Print array of strings in sorted order without copying one string into another Quick Links : ‘Practice Problems’ on Sorting ‘Quizzes’ on Sorting Recomended: Learn Data Structure and Algorithms | DSA Tutorial If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above. Last Updated : 30 Nov, 2023