pivot won' be too close to either end of the array howeverwhen the data is sorted or inversely sortedchoosing the pivot from one end or the other is bad idea can we improve on our approach to selecting the pivotmedian-of-three partitioning many schemes have been devised for picking better pivot the method should be simple but have good chance of avoiding the largest or smallest value picking an element at random is simple but--as we've seen--doesn' always result in good selection howeverwe could examine all the elements and actually calculate which one was the median this would be the ideal pivot choicebut the process isn' practicalas it would take more time than the sort itself compromise solution is to find the median of the firstlastand middle elements of the arrayand use this for the pivot picking the median of the firstlastand middle elements is called the median-of-three approach and is shown in figure left center right median is figure the median of three finding the median of three items is obviously much faster than finding the median of all the itemsand yet it successfully avoids picking the largest or smallest item in cases where the data is already sorted or inversely sorted there are probably some pathological arrangements of data where the median-of-three scheme works poorlybut normally it' fast and effective technique for finding the pivot besides picking the pivot more effectivelythe median-of-three approach has an additional benefitwe can dispense with the rightptr>left test in the second inside while loopleading to small increase in the algorithm' speed how is this possiblethe test can be eliminated because we can use the median-of-three approach to not only select the pivotbut also to sort the three elements used in the selection process figure shows this operation when these three elements are sortedand the median item is selected as the pivotwe are guaranteed that the element at the left end of the subarray is less than (or equal tothe pivotand the element at the right end is greater than (or equal tothe