I am learning Quick Sort. I know that Quick Sort performs badly when the pivot value does an unbalanced partition , and so first element or last element is not a good choice because if the list is almost sorted the partition would be unbalanced.
As i searched i found 2 options:
One was to choose a pivot randomly between low(lowest index) and up(highest index).It seems a safe option but random number generators are time consuming.
Second would be to take the median of all the elements. This option is costly so the median of first,last and middle element can be used as the pivot element.
Which method proves out to be the most efficient for Quick Sort?.. Is there any other method available for making the choice of pivot element?