Picking the pivot. Although the algorithm works no matter which element is chosen as pivot, some choices are better than others. In our implementation we use the last element as the pivot. The following is the recursion tree for the trace of Quicksort just given. Each call is labeled with a letter .
Calls occur in alphabetical order of their labels .
The pivot is in its final position. We can portray the recursion tree in such as case as follows. Quicksort will split the file into nearly equal halves on each call after having inspected and exchanged each element. The recursion tree in such a case can be roughly portrayed as shown below. The running time of qicksort is equal to the running time of the two recursive calls plus the linear time spent in the partition.