Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Sorting
  • MCQs on Sorting
  • Tutorial on Sorting
  • Bubble Sort
  • Quick Sort
  • Merge Sort
  • Insertion Sort
  • Selection Sort
  • Heap Sort
  • Sorting Complexities
  • Radix Sort
  • ShellSort
  • Counting Sort
  • Bucket Sort
  • TimSort
  • Bitonic Sort
  • Uses of Sorting Algorithm
Open In App
Next Article:
Introduction to Sorting Techniques – Data Structure and Algorithm Tutorials
Next article icon

Sorting Algorithms

Last Updated : 14 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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 of Sorting Algorithms:

  • 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, TimSort, Comb Sort, Pigeonhole Sort
Hybrid Sorting Algorithms : IntroSort, Tim Sort

Library Implementations:

  • qsort() in C
  • sort() in C++ STL
  • Arrays.sort() in Java with examples
  • Collections.sort() in Java with Examples
  • Sort a List in Python
  • Sorting in JavaScript

Easy Problems on Sorting:

  • Check if an array is Sorted
  • Sort an array of two types
  • Sort a String
  • Sort Each Row of a Matrix
  • Sort a Matrix
  • Sort a Linked List
  • Sort in Wave Form
  • Sort by Frequency
  • 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
  • Sorting Big Integers
  • Sort strings by lengths
  • Merge Two Sorted Arrays
  • Sort when two halves are sorted
  • 2 Sum - Pair in a Sorted Array
  • Intersection of two sorted arrays
  • Union of two sorted arrays
  • Meeting Rooms

Medium Problems on Sorting:

  • Minimum Increments to Make Unique
  • Merge Overlapping Intervals
  • Minimum Platforms
  • Closest Pair of Elements
  • Closest Pair of Points
  • Chocolate Distribution Problem
  • Min and Max Amount to Buy All
  • Three Way Partitioning
  • Sort an array of 0s, 1s and 2s
  • Sort a linked list of 0s, 1s and 2s
  • Inversion count
  • K-th Smallest Element
  • K Smallest Elements
  • 3 Sum - Find Any
  • 3 Sum - Closest Triplet
  • Smallest Difference Triplet from Three arrays
  • Merge K Sorted Arrays
  • Merge K Sorted Linked Lists
  • Min Unsorted Subarray to make array sorted
  • Sort a nearly sorted array
  • Sort n numbers in range from 0 to n^2 – 1
  • Sort an array of 1 to n
  • Sort according to order defined by another
  • Maximum intervals overlap
  • Permutation with worst Case of Merge Sort
  • Minimum swaps to make two arrays identical
  • Permute two arrays such that all pair suns are greater than K
  • Bucket Sort To Sort an Array with Negative Numbers
  • Convert an Array to reduced form using Vector of pairs
  • Check if array can be sorted with conditional swapping of adjacent
  • 4 Sum - Find Any [More problems an 4 Sum are in Hard Section]

Hard Problems on Sorting:

  • Merge Without Extra Space
  • Top K Frequent Elements
  • 3 Sum - Distinct Triplets
  • 4 Sum - Distinct Quadruples
  • 4 Sum - All Quadruples
  • 4 Sum - Closest Quadruple
  • Surpasser Counts in an Array
  • Count distinct occurrences as a subsequence
  • Minimum consecutive number subsets
  • Minimum swaps for Binary Tree to BST
  • K-th smallest element after removing some integers from natural numbers
  • Max frequency diff such greater freq item is also is also greater
  • Min swaps to reach permuted array with at most 2 positions left swaps allowed
  • Making Array Elements Same
  • Sort an array after applying an equation
  • Array of strings in sorted order without copying strings

Quick Links :

  • ‘Practice Problems’ on Sorting
  • Top Sorting Interview Questions
  • ‘Quizzes’ on Sorting

Recommended:

  • Learn Data Structure and Algorithms | DSA Tutorial

Next Article
Introduction to Sorting Techniques – Data Structure and Algorithm Tutorials

H

harendrakumar123
Improve
Article Tags :
  • Sorting
  • DSA
Practice Tags :
  • Sorting

Similar Reads

  • Sorting Algorithms
    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 differ
    3 min read
  • Introduction to Sorting Techniques – Data Structure and Algorithm Tutorials
    Sorting refers to rearrangement of 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. Why Sorting Algorithms are ImportantThe sorting algorithm is important in Com
    3 min read
  • Most Common Sorting Algorithms

    • Selection Sort
      Selection Sort is a comparison-based sorting algorithm. It sorts an array by repeatedly selecting the smallest (or largest) element from the unsorted portion and swapping it with the first unsorted element. This process continues until the entire array is sorted. First we find the smallest element a
      8 min read
    • Bubble Sort Algorithm
      Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm is not suitable for large data sets as its average and worst-case time complexity are quite high. We sort the array using multiple passes. After the fi
      8 min read
    • Insertion Sort Algorithm
      Insertion sort is a simple sorting algorithm that works by iteratively inserting each element of an unsorted list into its correct position in a sorted portion of the list. It is like sorting playing cards in your hands. You split the cards into two groups: the sorted cards and the unsorted cards. T
      9 min read
    • Merge Sort - Data Structure and Algorithms Tutorials
      Merge sort is a popular sorting algorithm known for its efficiency and stability. It follows the divide-and-conquer approach. It works by recursively dividing the input array into two halves, recursively sorting the two halves and finally merging them back together to obtain the sorted array. How do
      14 min read
    • Quick Sort
      QuickSort is a sorting algorithm based on the Divide and Conquer that picks an element as a pivot and partitions the given array around the picked pivot by placing the pivot in its correct position in the sorted array. It works on the principle of divide and conquer, breaking down the problem into s
      13 min read
    • Heap Sort - Data Structures and Algorithms Tutorials
      Heap sort is a comparison-based sorting technique based on Binary Heap Data Structure. It can be seen as an optimization over selection sort where we first find the max (or min) element and swap it with the last (or first). We repeat the same process for the remaining elements. In Heap Sort, we use
      14 min read
    • Counting Sort - Data Structures and Algorithms Tutorials
      Counting Sort is a non-comparison-based sorting algorithm. It is particularly efficient when the range of input values is small compared to the number of elements to be sorted. The basic idea behind Counting Sort is to count the frequency of each distinct element in the input array and use that info
      9 min read
    geeksforgeeks-footer-logo
    Corporate & Communications Address:
    A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
    Registered Address:
    K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
    GFG App on Play Store GFG App on App Store
    Advertise with us
    • Company
    • About Us
    • Legal
    • Privacy Policy
    • In Media
    • Contact Us
    • Advertise with us
    • GFG Corporate Solution
    • Placement Training Program
    • Languages
    • Python
    • Java
    • C++
    • PHP
    • GoLang
    • SQL
    • R Language
    • Android Tutorial
    • Tutorials Archive
    • DSA
    • Data Structures
    • Algorithms
    • DSA for Beginners
    • Basic DSA Problems
    • DSA Roadmap
    • Top 100 DSA Interview Problems
    • DSA Roadmap by Sandeep Jain
    • All Cheat Sheets
    • Data Science & ML
    • Data Science With Python
    • Data Science For Beginner
    • Machine Learning
    • ML Maths
    • Data Visualisation
    • Pandas
    • NumPy
    • NLP
    • Deep Learning
    • Web Technologies
    • HTML
    • CSS
    • JavaScript
    • TypeScript
    • ReactJS
    • NextJS
    • Bootstrap
    • Web Design
    • Python Tutorial
    • Python Programming Examples
    • Python Projects
    • Python Tkinter
    • Python Web Scraping
    • OpenCV Tutorial
    • Python Interview Question
    • Django
    • Computer Science
    • Operating Systems
    • Computer Network
    • Database Management System
    • Software Engineering
    • Digital Logic Design
    • Engineering Maths
    • Software Development
    • Software Testing
    • DevOps
    • Git
    • Linux
    • AWS
    • Docker
    • Kubernetes
    • Azure
    • GCP
    • DevOps Roadmap
    • System Design
    • High Level Design
    • Low Level Design
    • UML Diagrams
    • Interview Guide
    • Design Patterns
    • OOAD
    • System Design Bootcamp
    • Interview Questions
    • Inteview Preparation
    • Competitive Programming
    • Top DS or Algo for CP
    • Company-Wise Recruitment Process
    • Company-Wise Preparation
    • Aptitude Preparation
    • Puzzles
    • School Subjects
    • Mathematics
    • Physics
    • Chemistry
    • Biology
    • Social Science
    • English Grammar
    • Commerce
    • World GK
    • GeeksforGeeks Videos
    • DSA
    • Python
    • Java
    • C++
    • Web Development
    • Data Science
    • CS Subjects
    @GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
    We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
    Lightbox
    Improvement
    Suggest Changes
    Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
    geeksforgeeks-suggest-icon
    Create Improvement
    Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
    geeksforgeeks-improvement-icon
    Suggest Changes
    min 4 words, max Words Limit:1000

    Thank You!

    Your suggestions are valuable to us.

    What kind of Experience do you want to share?

    Interview Experiences
    Admission Experiences
    Career Journeys
    Work Experiences
    Campus Experiences
    Competitive Exam Experiences