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 Divide and Conquer
  • MCQs on Divide and Conquer
  • Tutorial on Divide & Conquer
  • Binary Search
  • Merge Sort
  • Quick Sort
  • Calculate Power
  • Strassen's Matrix Multiplication
  • Karatsuba Algorithm
  • Divide and Conquer Optimization
  • Closest Pair of Points
Open In App
Next Article:
Time and Space Complexity Analysis of Quick Sort
Next article icon

Quick Sort

Last Updated : 17 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
Try it on GfG Practice
redirect icon

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 smaller sub-problems.

There are mainly three steps in the algorithm:

  1. Choose a Pivot: Select an element from the array as the pivot. The choice of pivot can vary (e.g., first element, last element, random element, or median).
  2. Partition the Array: Rearrange the array around the pivot. After partitioning, all elements smaller than the pivot will be on its left, and all elements greater than the pivot will be on its right. The pivot is then in its correct position, and we obtain the index of the pivot.
  3. Recursively Call: Recursively apply the same process to the two partitioned sub-arrays (left and right of the pivot).
  4. Base Case: The recursion stops when there is only one element left in the sub-array, as a single element is already sorted.

Here’s a basic overview of how the QuickSort algorithm works.

Heap-Sort-Recursive-Illustration

Choice of Pivot

There are many different choices for picking pivots.

  • Always pick the first (or last) element as a pivot. The below implementation picks the last element as pivot. The problem with this approach is it ends up in the worst case when array is already sorted.
  • Pick a random element as a pivot. This is a preferred approach because it does not have a pattern for which the worst case happens.
  • Pick the median element is pivot. This is an ideal approach in terms of time complexity as we can find median in linear time and the partition function will always divide the input array into two halves. But it takes more time on average as median finding has high constants.

Partition Algorithm

The key process in quickSort is a partition(). There are three common algorithms to partition. All these algorithms have O(n) time complexity.

  1. Naive Partition: Here we create copy of the array. First put all smaller elements and then all greater. Finally we copy the temporary array back to original array. This requires O(n) extra space.
  2. Lomuto Partition: We have used this partition in this article. This is a simple algorithm, we keep track of index of smaller elements and keep swapping. We have used it here in this article because of its simplicity.
  3. Hoare’s Partition: This is the fastest of all. Here we traverse array from both sides and keep swapping greater element on left with smaller on right while the array is not partitioned. Please refer Hoare’s vs Lomuto for details.

Working of Lomuto Partition Algorithm with Illustration

The logic is simple, we start from the leftmost element and keep track of the index of smaller (or equal) elements as i . While traversing, if we find a smaller element, we swap the current element with arr[i]. Otherwise, we ignore the current element.

Let us understand the working of partition algorithm with the help of the following example:


Illustration of QuickSort Algorithm

In the previous step, we looked at how the partitioning process rearranges the array based on the chosen pivot. Next, we apply the same method recursively to the smaller sub-arrays on the left and right of the pivot. Each time, we select new pivots and partition the arrays again. This process continues until only one element is left, which is always sorted. Once every element is in its correct position, the entire array is sorted.

Below image illustrates, how the recursive method calls for the smaller sub-arrays on the left and right of the pivot:

quick-sort--images

Quick Sort is a crucial algorithm in the industry, but there are other sorting algorithms that may be more optimal in different cases.

C++
#include <bits/stdc++.h> using namespace std;  int partition(vector<int>& arr, int low, int high) {        // Choose the pivot     int pivot = arr[high];        // Index of smaller element and indicates      // the right position of pivot found so far     int i = low - 1;      // Traverse arr[low..high] and move all smaller     // elements on left side. Elements from low to      // i are smaller after every iteration     for (int j = low; j <= high - 1; j++) {         if (arr[j] < pivot) {             i++;             swap(arr[i], arr[j]);         }     }          // Move pivot after smaller elements and     // return its position     swap(arr[i + 1], arr[high]);       return i + 1; }  // The QuickSort function implementation void quickSort(vector<int>& arr, int low, int high) {        if (low < high) {                // pi is the partition return index of pivot         int pi = partition(arr, low, high);          // Recursion calls for smaller elements         // and greater or equals elements         quickSort(arr, low, pi - 1);         quickSort(arr, pi + 1, high);     } }  int main() {     vector<int> arr = {10, 7, 8, 9, 1, 5};     int n = arr.size();     quickSort(arr, 0, n - 1);        for (int i = 0; i < n; i++) {         cout << arr[i] << " ";     }     return 0; } 
C
#include <stdio.h>  void swap(int* a, int* b);  // Partition function int partition(int arr[], int low, int high) {          // Choose the pivot     int pivot = arr[high];          // Index of smaller element and indicates      // the right position of pivot found so far     int i = low - 1;      // Traverse arr[low..high] and move all smaller     // elements to the left side. Elements from low to      // i are smaller after every iteration     for (int j = low; j <= high - 1; j++) {         if (arr[j] < pivot) {             i++;             swap(&arr[i], &arr[j]);         }     }          // Move pivot after smaller elements and     // return its position     swap(&arr[i + 1], &arr[high]);       return i + 1; }  // The QuickSort function implementation void quickSort(int arr[], int low, int high) {     if (low < high) {                  // pi is the partition return index of pivot         int pi = partition(arr, low, high);          // Recursion calls for smaller elements         // and greater or equals elements         quickSort(arr, low, pi - 1);         quickSort(arr, pi + 1, high);     } }  void swap(int* a, int* b) {     int t = *a;     *a = *b;     *b = t; }  int main() {     int arr[] = {10, 7, 8, 9, 1, 5};     int n = sizeof(arr) / sizeof(arr[0]);      quickSort(arr, 0, n - 1);     for (int i = 0; i < n; i++) {         printf("%d ", arr[i]);     }          return 0; } 
Java
import java.util.Arrays;  class GfG {      // Partition function     static int partition(int[] arr, int low, int high) {                  // Choose the pivot         int pivot = arr[high];                  // Index of smaller element and indicates          // the right position of pivot found so far         int i = low - 1;          // Traverse arr[low..high] and move all smaller         // elements to the left side. Elements from low to          // i are smaller after every iteration         for (int j = low; j <= high - 1; j++) {             if (arr[j] < pivot) {                 i++;                 swap(arr, i, j);             }         }                  // Move pivot after smaller elements and         // return its position         swap(arr, i + 1, high);           return i + 1;     }      // Swap function     static void swap(int[] arr, int i, int j) {         int temp = arr[i];         arr[i] = arr[j];         arr[j] = temp;     }      // The QuickSort function implementation     static void quickSort(int[] arr, int low, int high) {         if (low < high) {                          // pi is the partition return index of pivot             int pi = partition(arr, low, high);              // Recursion calls for smaller elements             // and greater or equals elements             quickSort(arr, low, pi - 1);             quickSort(arr, pi + 1, high);         }     }      public static void main(String[] args) {         int[] arr = {10, 7, 8, 9, 1, 5};         int n = arr.length;                quickSort(arr, 0, n - 1);                  for (int val : arr) {             System.out.print(val + " ");           }     } } 
Python
# Partition function def partition(arr, low, high):          # Choose the pivot     pivot = arr[high]          # Index of smaller element and indicates      # the right position of pivot found so far     i = low - 1          # Traverse arr[low..high] and move all smaller     # elements to the left side. Elements from low to      # i are smaller after every iteration     for j in range(low, high):         if arr[j] < pivot:             i += 1             swap(arr, i, j)          # Move pivot after smaller elements and     # return its position     swap(arr, i + 1, high)     return i + 1  # Swap function def swap(arr, i, j):     arr[i], arr[j] = arr[j], arr[i]  # The QuickSort function implementation def quickSort(arr, low, high):     if low < high:                  # pi is the partition return index of pivot         pi = partition(arr, low, high)                  # Recursion calls for smaller elements         # and greater or equals elements         quickSort(arr, low, pi - 1)         quickSort(arr, pi + 1, high)  # Main driver code if __name__ == "__main__":     arr = [10, 7, 8, 9, 1, 5]     n = len(arr)      quickSort(arr, 0, n - 1)          for val in arr:         print(val, end=" ")  
C#
using System;  class GfG {      // Partition function     static int Partition(int[] arr, int low, int high) {                  // Choose the pivot         int pivot = arr[high];                  // Index of smaller element and indicates          // the right position of pivot found so far         int i = low - 1;          // Traverse arr[low..high] and move all smaller         // elements to the left side. Elements from low to          // i are smaller after every iteration         for (int j = low; j <= high - 1; j++) {             if (arr[j] < pivot) {                 i++;                 Swap(arr, i, j);             }         }                  // Move pivot after smaller elements and         // return its position         Swap(arr, i + 1, high);           return i + 1;     }      // Swap function     static void Swap(int[] arr, int i, int j) {         int temp = arr[i];         arr[i] = arr[j];         arr[j] = temp;     }      // The QuickSort function implementation     static void QuickSort(int[] arr, int low, int high) {         if (low < high) {                          // pi is the partition return index of pivot             int pi = Partition(arr, low, high);              // Recursion calls for smaller elements             // and greater or equals elements             QuickSort(arr, low, pi - 1);             QuickSort(arr, pi + 1, high);         }     }      static void Main(string[] args) {         int[] arr = {10, 7, 8, 9, 1, 5};         int n = arr.Length;          QuickSort(arr, 0, n - 1);         foreach (int val in arr) {             Console.Write(val + " ");          }     } } 
JavaScript
// Partition function function partition(arr, low, high) {      // Choose the pivot     let pivot = arr[high];      // Index of smaller element and indicates     // the right position of pivot found so far     let i = low - 1;      // Traverse arr[low..high] and move all smaller     // elements to the left side. Elements from low to     // i are smaller after every iteration     for (let j = low; j <= high - 1; j++) {         if (arr[j] < pivot) {             i++;             swap(arr, i, j);         }     }      // Move pivot after smaller elements and     // return its position     swap(arr, i + 1, high);     return i + 1; }  // Swap function function swap(arr, i, j) {     let temp = arr[i];     arr[i] = arr[j];     arr[j] = temp; }  // The QuickSort function implementation function quickSort(arr, low, high) {     if (low < high) {          // pi is the partition return index of pivot         let pi = partition(arr, low, high);          // Recursion calls for smaller elements         // and greater or equals elements         quickSort(arr, low, pi - 1);         quickSort(arr, pi + 1, high);     } }  // Main driver code let arr = [ 10, 7, 8, 9, 1, 5 ]; let n = arr.length;  // Call QuickSort on the entire array quickSort(arr, 0, n - 1); for (let i = 0; i < arr.length; i++) {     console.log(arr[i] + " "); } 
PHP
<?php // Function to swap two elements function swap(&$a, &$b) {     $temp = $a;     $a = $b;     $b = $temp; }  // Partition function function partition(&$arr, $low, $high) {          // Choose the pivot     $pivot = $arr[$high];          // Index of smaller element and indicates      // the right position of pivot found so far     $i = $low - 1;      // Traverse arr[low..high] and move all smaller     // elements to the left side. Elements from low to      // i are smaller after every iteration     for ($j = $low; $j <= $high - 1; $j++) {         if ($arr[$j] < $pivot) {             $i++;             swap($arr[$i], $arr[$j]);         }     }          // Move pivot after smaller elements and     // return its position     swap($arr[$i + 1], $arr[$high]);       return $i + 1; }  // The QuickSort function implementation function quickSort(&$arr, $low, $high) {     if ($low < $high) {                  // pi is the partition return index of pivot         $pi = partition($arr, $low, $high);          // Recursion calls for smaller elements         // and greater or equals elements         quickSort($arr, $low, $pi - 1);         quickSort($arr, $pi + 1, $high);     } }  // Main driver code $arr = array(10, 7, 8, 9, 1, 5); $n = count($arr);  quickSort($arr, 0, $n - 1); for ($i = 0; $i < count($arr); $i++) {     echo $arr[$i] . " ";   } ?> 

Output
Sorted Array 1 5 7 8 9 10 

Complexity Analysis of Quick Sort

Time Complexity:

  • Best Case: (Ω(n log n)), Occurs when the pivot element divides the array into two equal halves.
  • Average Case (θ(n log n)), On average, the pivot divides the array into two parts, but not necessarily equal.
  • Worst Case: (O(n²)), Occurs when the smallest or largest element is always chosen as the pivot (e.g., sorted arrays).

Auxiliary Space: O(n), due to recursive call stack

Please refer Time and Space Complexity Analysis of Quick Sort for more details.

Advantages of Quick Sort

  • It is a divide-and-conquer algorithm that makes it easier to solve problems.
  • It is efficient on large data sets.
  • It has a low overhead, as it only requires a small amount of memory to function.
  • It is Cache Friendly as we work on the same array to sort and do not copy data to any auxiliary array.
  • Fastest general purpose algorithm for large data when stability is not required.
  • It is tail recursive and hence all the tail call optimization can be done.

Disadvantages of Quick Sort

  • It has a worst-case time complexity of O(n2), which occurs when the pivot is chosen poorly.
  • It is not a good choice for small data sets.
  • It is not a stable sort, meaning that if two elements have the same key, their relative order will not be preserved in the sorted output in case of quick sort, because here we are swapping elements according to the pivot’s position (without considering their original positions).

Applications of Quick Sort

Please refer Application of Quicksort for more details.



Next Article
Time and Space Complexity Analysis of Quick Sort
author
kartik
Improve
Article Tags :
  • Divide and Conquer
  • DSA
  • Sorting
  • Adobe
  • DSA Tutorials
  • Goldman Sachs
  • HSBC
  • Qualcomm
  • Quick Sort
  • Samsung
  • SAP Labs
  • Target Corporation
Practice Tags :
  • Adobe
  • Goldman Sachs
  • HSBC
  • Qualcomm
  • Samsung
  • SAP Labs
  • Target Corporation
  • Divide and Conquer
  • Sorting

Similar Reads

  • 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
  • Time and Space Complexity Analysis of Quick Sort
    The time complexity of Quick Sort is O(n log n) on average case, but can become O(n^2) in the worst-case. The space complexity of Quick Sort in the best case is O(log n), while in the worst-case scenario, it becomes O(n) due to unbalanced partitioning causing a skewed recursion tree that requires a
    4 min read
  • Application and uses of Quicksort
    Quicksort: Quick sort is a Divide Conquer algorithm and the fastest sorting algorithm. In quick sort, it creates two empty arrays to hold elements less than the pivot element and the element greater than the pivot element and then recursively sort the sub-arrays. There are many versions of Quicksort
    2 min read
  • QuickSort using different languages

    • C++ Program for Quick Sort
      Quick Sort is one of the most efficient sorting algorithms available to sort the given dataset. It is known for its efficiency in handling large datasets which made it a go-to choice for programmers looking to optimize their code. In C++, the STL's sort() function uses a mix of different sorting alg
      4 min read

    • Java Program for QuickSort
      Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of QuickSort that pick pivot in different ways. Always pick first element as pivot.Always pick last element as pivot (i
      2 min read

    • QuickSort - Python
      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. How does QuickSort Algorithm work?QuickSort works on the principle of divide and
      4 min read

    • p5.js | Quick Sort
      QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways. Always pick first element as pivot. Always pick last element as pivot. Pick a random ele
      3 min read

    Iterative QuickSort

    • Iterative Quick Sort
      Following is a typical recursive implementation of Quick Sort that uses last element as pivot. [GFGTABS] C++ // CPP code for recursive function of Quicksort #include <bits/stdc++.h> using namespace std; /* This function takes last element as pivot, places the pivot element at its correct posit
      15+ min read

    • C Program for Iterative Quick Sort
      C/C++ Code // An iterative implementation of quick sort #include &lt;stdio.h&gt; // A utility function to swap two elements void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } /* This function is same in both iterative and recursive*/ int partition(int arr[], int l, int h) { int x = a
      4 min read

    • Java Program for Iterative Quick Sort
      Below is the implementation of Iterative Quick Sort: [GFGTABS] Java // Java implementation of iterative quick sort import java.io.*; public class IterativeQuickSort { void swap(int arr[], int i, int j) { int t = arr[i]; arr[i] = arr[j]; arr[j] = t; } /* This function is same in both iterative and re
      3 min read

    • Python Program for Iterative Quick Sort
      The code consists of two main functions: partition and quickSortIterative, along with a driver code to test the sorting process. The partition function is used for the process of partitioning a given subarray into two parts - elements less than or equal to the chosen pivot (arr[h]) on the left and e
      4 min read

    Different implementations of QuickSort

    • QuickSort using Random Pivoting
      In this article, we will discuss how to implement QuickSort using random pivoting. In QuickSort we first partition the array in place such that all elements to the left of the pivot element are smaller, while all elements to the right of the pivot are greater than the pivot. Then we recursively call
      15+ min read

    • QuickSort Tail Call Optimization (Reducing worst case space to Log n )
      Prerequisite : Tail Call Elimination In QuickSort, partition function is in-place, but we need extra space for recursive function calls. A simple implementation of QuickSort makes two calls to itself and in worst case requires O(n) space on function call stack. The worst case happens when the select
      11 min read

    • Implement Quicksort with first element as pivot
      QuickSort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given array around the pivot. There are many different versions of quickSort that pick the pivot in different ways.  Always pick the first element as a pivot.Always pick the last element as a pivot.Pick a
      13 min read

    • Advanced Quick Sort (Hybrid Algorithm)
      Prerequisites: Insertion Sort, Quick Sort, Selection SortIn this article, a Hybrid algorithm with the combination of quick sort and insertion sort is implemented. As the name suggests, the Hybrid algorithm combines more than one algorithm. Why Hybrid algorithm: Quicksort algorithm is efficient if th
      9 min read

    • Quick Sort using Multi-threading
      QuickSort is a popular sorting technique based on divide and conquer algorithm. In this technique, an element is chosen as a pivot and the array is partitioned around it. The target of partition is, given an array and an element x of the array as a pivot, put x at its correct position in a sorted ar
      9 min read

    • Stable QuickSort
      A sorting algorithm is said to be stable if it maintains the relative order of records in the case of equality of keys. Input : (1, 5), (3, 2) (1, 2) (5, 4) (6, 4) We need to sort key-value pairs in the increasing order of keys of first digit There are two possible solution for the two pairs where t
      9 min read

    • Dual pivot Quicksort
      As we know, the single pivot quick sort takes a pivot from one of the ends of the array and partitioning the array, so that all elements are left to the pivot are less than or equal to the pivot, and all elements that are right to the pivot are greater than the pivot.The idea of dual pivot quick sor
      10 min read

    • 3-Way QuickSort (Dutch National Flag)
      In simple QuickSort algorithm, we select an element as pivot, partition the array around a pivot and recur for subarrays on the left and right of the pivot. Consider an array which has many redundant elements. For example, {1, 4, 2, 4, 2, 4, 1, 2, 4, 1, 2, 2, 2, 2, 4, 1, 4, 4, 4}. If 4 is picked as
      15+ min read

    Visualization of QuickSort

    • Sorting Algorithm Visualization : Quick Sort
      An algorithm like Quicksort algorithm is hard to understand theoretically. We can understand easily by visualizing such kind of algorithms. In this article, a program that visualizes the Quicksort Algorithm has been implemented.The Graphical User Interface(GUI) is implemented in python using pygame
      3 min read

    • Visualizing Quick Sort using Tkinter in Python
      Prerequisite: QuickSort Tkinter is a very easy-to-use and beginner-friendly GUI library that can be used to visualize the sorting algorithms. Here Quick Sort Algorithm is visualized which is a divide and conquer algorithm. It first considers a pivot element then, creates two subarrays to hold elemen
      7 min read

    • Visualization of Quick sort using Matplotlib
      Visualizing algorithms makes it easier to understand them by analyzing and comparing the number of operations that took place to compare and swap the elements. For this we will use matplotlib, to plot bar graphs to represent the elements of the array, Approach : We will generate an array with random
      3 min read

    • 3D Visualisation of Quick Sort using Matplotlib in Python
      Visualizing algorithms makes it easier to understand them by analyzing and comparing the number of operations that took place to compare and swap the elements. 3D visualization of algorithms is less common, for this we will use Matplotlib to plot bar graphs and animate them to represent the elements
      3 min read

    Partitions in QuickSort

    • Hoare's vs Lomuto partition scheme in QuickSort
      We have discussed the implementation of QuickSort using Lomuto partition scheme. Lomuto's partition scheme is easy to implement as compared to Hoare scheme. This has inferior performance to Hoare's QuickSort. Lomuto's Partition Scheme: This algorithm works by assuming the pivot element as the last e
      15+ min read

    • Quick Sort(Hoare's Partition) Visualization using JavaScript
      GUI(Graphical User Interface) helps in better understanding than programs. In this article, we will visualize Quick Sort using JavaScript. We will see how the array is being partitioned into two parts and how we get the final sorted array. We will also visualize the time complexity of Quick Sort. Re
      4 min read

    • Quick Sort(Lomuto Partition) Visualization using JavaScript
      GUI(Graphical User Interface) helps in better in understanding than programs. In this article, we will visualize Quick Sort using JavaScript. We will see how the array is being partitioned using Lomuto Partition and then how we get the final sorted array. We will also visualize the time complexity o
      4 min read

    • Implement Various Types of Partitions in Quick Sort in Java
      Quicksort is a Divide and Conquer Algorithm that is used for sorting the elements. In this algorithm, we choose a pivot and partitions the given array according to the pivot. Quicksort algorithm is a mostly used algorithm because this algorithm is cache-friendly and performs in-place sorting of the
      7 min read

    Some problems on QuickSort

    • QuickSort on Singly Linked List
      Given a linked list, apply the Quick sort algorithm to sort the linked list. To sort the Linked list change pointers rather than swapping data. Example: Input: 5->4->1->3->2Output: 1->2->3->4->5Input: 4->3->2->1Output: 1->2->3->4 Approach: The Quick Sort alg
      13 min read

    • QuickSort on Doubly Linked List
      Given a doubly linked list, the task is to sort the doubly linked list in non-decreasing order using the quicksort. Examples: Input: head: 5<->3<->4<->1<->2Output: 1<->2<->3<->4<->5Explanation: Doubly Linked List after sorting using quicksort technique
      12 min read

    • Nuts & Bolts Problem (Lock & Key problem) using Quick Sort
      Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Constraint: Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means a nut can only be compared with a bolt and a
      12 min read

  • Is Quick Sort Algorithm Adaptive or not
    Adaptive sorting algorithms are designed to take advantage of existing order in the input data. This means, if the array is already sorted or partially sorted, an adaptive algorithm will recognize that and sort the array faster than it would for a completely random array. Quick Sort is not an adapti
    6 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