Intermediate 25 min

What is Quick Sort?

Quick Sort is a divide-and-conquer sorting algorithm. It picks a pivot element, partitions the array around it, then recursively sorts the sub-arrays. It’s one of the fastest general-purpose sorting algorithms.

The Basic Idea

Quick sort works by:

Pick Pivot Partition Sort Left Sort Right Sorted!

Why Quick Sort is Fast

Quick sort is efficient because:

  1. Divide-and-conquer: Splits problem into smaller sub-problems
  2. In-place: Uses O(log n) extra space (for recursion)
  3. Average case: O(n log n) time complexity
  4. Cache-friendly: Good locality of reference

Visual Example

Watch quick sort in action:

Quick Sort Visualization

1x

Click play to see how the algorithm partitions and sorts the array.

Key Characteristics

  • Average time: O(n log n) - very fast
  • Worst time: O(n²) - rare with good pivot selection
  • Space: O(log n) - for recursion stack
  • Stable: No - equal elements may change order
  • In-place: Yes - sorts the original array

Real-World Use

Quick sort is used in:

  • Standard library implementations (C++ std::sort, Java Arrays.sort)
  • Database systems
  • Operating systems
  • Many production applications

What’s Next?

Now that you know what quick sort is, let’s see exactly how it works.

Progress 14%
Page 1 of 7
Previous Next