Whats a pivot?

A number you select to make it your focus on that iteration.


What does a pivot do?

Meanwhile, the rest of the array is unordered (or not), the pivot ends its iteration on the right place. Why? Because you put everyone smaller than it on its left side, and every bigger element on its right side.


What makes a good pivot?

At the end of your iteration, the closer it is to the middle of the selected interval the better.

Getting repeatedly a pivot that ends at one of the extremities of your interval makes the algorithm a lot slower (maybe O(n²), if you are unlucky).


How to get a good pivot?

Median of three

You get the start, the middle and the end of your interval. Then, get the element between the other two. It makes you never get the biggest or the smallest element.

Random number

Just pick a random number on the wanted range. It’s almost impossible for it to get the worst scenario every time.


Partitioning

The method that rearranges the array based on the pivot.