Pseudo Code
Lesson 4 of 9 in Coddy's Quick Sort - DSA Series course.
quickSort(array):
if length(array) <= 1:
return array
pivot = last element of array
less = elements (except pivot) that are < pivot
rest = elements (except pivot) that are >= pivot
return quickSort(less) + [pivot] + quickSort(rest)How it maps to the idea:
- pivot is the element we compare everything against. Here it is always the last element.
- less collects every element smaller than the pivot; rest collects the others.
- Recursively sorting less and rest and placing the pivot between them yields a fully sorted array, because everything in less belongs before the pivot and everything in rest belongs after it.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Quick Sort - DSA Series
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)