Skip to content
SortingMediumLeetCode #912

Quick Sort

Divide-and-conquer algorithm that picks a pivot and partitions the array around it recursively.

Time O(n log n) Space O(log n)
Open in 3D Studio

Live loop — open the studio to scrub, add your own array, or race it in Battle Arena.

Asked in interviews at

GoogleAmazonUberMicrosoft

Reference implementation (Python)

def quick_sort(arr, low, high):
    if low < high:
        pi = partition(arr, low, high)
        quick_sort(arr, low, pi - 1)
        quick_sort(arr, pi + 1, high)

def partition(arr, low, high):
    pivot = arr[high]
    i = low - 1
    for j in range(low, high):
        if arr[j] < pivot:
            i += 1
            arr[i], arr[j] = arr[j], arr[i]
    arr[i + 1], arr[high] = arr[high], arr[i + 1]
    return i + 1

Embed this visualization

Drop a live, looping Quick Sort canvas into a blog post or course page.

<iframe src="/embed/quick-sort" width="100%" height="380" style="border:1px solid #e6e8ec;border-radius:14px" loading="lazy" title="3D algorithm visualization by CodeWithMunnaX"></iframe>

Frequently asked

What is the time and space complexity of Quick Sort?

Quick Sort runs in O(n log n) time and O(log n) auxiliary space.

Is the Quick Sort visualizer free?

The core 3D visualizer, Web Audio chimes and step intuition are free. A one-time ₹49 Pro Pass unlocks advanced algorithms, large custom arrays, Battle Arena and reel export.

Which companies ask Quick Sort in interviews?

Quick Sort shows up in interviews at Google, Amazon, Uber, Microsoft.

How does the 3D visualization of Quick Sort work?

Each array value becomes a 3D pillar whose height maps to its value. Comparisons glow amber, swaps flash red, and settled elements lock green while a floating pointer badge tracks the active index — synchronized line-by-line with the Python code.

More Sorting