← All Exercises

Quicksort Implementation

advancedjavascript~30min

Background

Quicksort is a divide-and-conquer sorting algorithm with O(n log n) average time complexity, widely used in practice.

Problem

Write a function that sorts an array of numbers using the quicksort algorithm with Lomuto partition scheme and median-of-three pivot selection.

Input

An array of numbers to sort.

Output

A new array sorted in ascending order.

Sample tests

Sample 1

Input: [3, 6, 8, 10, 1, 2, 1]
Expected: [1, 1, 2, 3, 6, 8, 10]

Your solution

Learning objective

Master divide-and-conquer sorting and understand pivot selection strategies.