Sorting

Problem shape

Intermediate
4
8
15
16
23
42
Core idea

Partition values around a pivot, then recursively sort both sides.

Step 1 / 5
Problem shape
Current lesson

Quick Sort Lab

Sorting Intermediate

Quick Sort

Welcome to the Quick Sort algorithm lab. Partition values around a pivot, then recursively sort both sides. Use it when: Use for fast in-place general sorting with good pivot selection. The time complexity is Average O(n log n), worst O(n^2), and the space complexity is O(log n). The pseudocode is: quick(left, right) if left >= right return pivot = partition(left, right) quick(left, pivot - 1) quick(pivot + 1, right) As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

Average O(n log n), worst O(n^2)

Space

O(log n)

Pseudocode

quick(left, right)
  if left >= right return
  pivot = partition(left, right)
  quick(left, pivot - 1)
  quick(pivot + 1, right)
Open deeper structure lesson
1.0x