Published in

basecs

# A quick study on quicksort basics

1. First, quicksort determines something called a pivot, which is a somewhat arbitrary element in the collection.
2. Next, using the pivot point, it partitions (or divides) the larger unsorted collection into two, smaller lists. It uses some smart logic to decide how to do the partitioning: it moves all the elements smaller than the pivot to the left (before) the pivot element, and moves all the elements larger than the pivot to the right (after) the pivot element.

Even though the list isn’t completely sorted yet, we know that the items are in the correct order in relation to the pivot. This means that we never have to compare elements on the left side of the partition to elements on the right side of the partition. We already know they are in their correct spots in relation to the pivot.

# Quick-fire swapping

If the quicksort algorithm determines that two elements are out of order, it leans on its references to swap them into their correct place in the collection.

However — if both the `left` reference is greater than the pivot and the `right` reference is smaller than the pivot, we know that we’ve stumbled upon two elements that are out of order.

# Resources

1. Quicksort algorithm, mycodeschool
2. Sorting Algorithms: QuickSort, Professor Lydia Sinapova
3. Quick Sort, Computerphile
4. Data Structure and Algorithms — Quick Sort, Tutorialspoint
5. QuickSort, GeeksForGeeks
6. Quick Sort in 4 Minutes, Michael Sambol

--

--

## More from basecs

Exploring the basics of computer science, every Monday, for a year.

## Get the Medium app

Writing words, writing code. Sometimes doing both at once.