Searching & Sorting AlgorithmsIntermediate LevelStudy Time: 25 mins

Quick Sort Algorithm

Quick Sort is a Divide and Conquer algorithm that selects a pivot element, partitions the array around the pivot, and recursively sorts the sub-arrays.

Loading visualizer workspace...

Real-world analogy: Height Line Sorting

Pivot
Hover over items for details

Pick a person as pivot. Everyone shorter moves to the left, everyone taller moves to the right. Repeat recursively for left and right groups.

  • Pivot= Element chosen to partition the dataset into left/right subsets.

Complexity analysis

Scenario Simulator: Dataset Size (N = 500)
Presets:
N = 10N = 10,000
Complexity Curve MapQuick Sort: O(N log N) Linearithmic Time
Time (t)Size N (500)N = 500O(N²)O(N log N)O(N)O(log N)O(1)Quick Sort Divid
Time Steps (N=500)

~4,483 steps (Linearithmic)

O(N log N) Linearithmic Time

Space Footprint

O(log N) Stack

Memory growth rate as N expands.

Performance Rank
Moderate Tier

Relative efficiency rating for large N.

OperationTime ComplexitySpace Complexity
Best / Average CaseO(N log N)O(log N)
Worst Case (Sorted Array w/ bad pivot)O(N²)O(N)

Code implementations

function quickSort(arr, low = 0, high = arr.length - 1) {
  if (low < high) {
    const pi = partition(arr, low, high);
    quickSort(arr, low, pi - 1);
    quickSort(arr, pi + 1, high);
  }
  return arr;
}

Real-world applications

Case 01

System Sorting Primitives

Powers C qsort() and C++ std::sort (Introsort).

Interview questions

Topic Knowledge Test & Assessment

10 Questions Assessment

Quick Sort Knowledge & Skill Test

Validate your conceptual understanding, operation mechanics, and core concepts of Quick Sort.