Linear-time Partitioning
We'll cover the following...
The real work of quicksort happens during the divide step, which partitions subarray
Having chosen a pivot, we partition the subarray by going through it, left to right, comparing each element with the pivot. We maintain two indices q
and j
into the subarray that divide it up into four groups. We use the variable name q
because that index will eventually point at our pivot. We use j
because it's a common counter variable name, and the variable will be discarded once we're done.
The elements in
...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy