How Many Comparisons Does Quicksort Use?
暂无分享,去创建一个
Abstract We examine the probability distribution of the number of comparisons needed by the Quicksort sorting algorithm, where probability arises due to the items being in random order. We develop a general class of distributions for the permutation of the items to be sorted which includes the uniform distribution on permutations as a special case. For this general class, the distribution of the number of comparisons is given by the solution of a simple recurrence relation. We provide an exact solution of the recurrence for very small n. We show that the solution can be approximated asymptotically by the solution of a "quadratic" operator equation. We exhibit three numerical solutions to the operator equation for two different distributions on permutations from the general class. We also exhibit numerical solutions for the case in which the algorithm is modified so that arrays are partitioned by the median-of-three selected items rather than by a single selected item.