Divide & Conquer: Quick Sort

HardAcc. 72.2%
+50 XP 25

The Pivot Strategy (QuickSort)

QuickSort is a high-speed "Divide and Conquer" algorithm. It picks a "Pivot" point and splits the world into two sides: those smaller than the pivot and those larger. By doing this recursively, the array is sorted at lightning speed.

The Assignment

Your mission is to implement the recursive QuickSort protocol. Your function receives data.

  1. Use a helper function for the partition logic (Lomuto Partition).
  2. Choose the last element as the pivot.
  3. Partition the array such that all smaller elements move to the left of the pivot.
  4. Recursively sort the left and right halves.
  5. Print the final sorted result (space-separated).

01EXAMPLE 1

Input[10, 7, 8, 9, 1, 5]
Output1 5 7 8 9 10

Explanation: Sorted using recursive partitioning.

Constraints

  • O(n log n) average time complexity.
  • Must use recursion.
AlgorithmsSortingRecursion
JavaScript
Loading...
1 Hidden

Input Arguments

data[10,7,8,9,1,5]

Expected Output

1 5 7 8 9 10

Click RUN to test your solution