Asymptotic expansions for moments of number of comparisons

Asymptotic expansions for moments of number of comparisons
used by the randomized quick sort algorithm

Sumit Kumar Jha Center for Security, Theory, and Algorithmic Research
International Institute of Information Technology, Hyderabad, India

We calculate asymptotic expansions for the moments of number of comparisons used by the randomized quick sort algorithm using the singularity analysis of certain generating functions.

1. Introduction

The basic quick sort algorithm recursively sorts numbers in an array by partitioning the input array into two independent and smaller subarrays, and thereafter sorting these subarrays. The partitioning procedure chooses the first or last element of the array as pivot and puts it in its right place so that numbers to the left of it are smaller than it, and those appearing to the right of it are larger than it.

For purposes of this analysis we assume that the input array to the quick sort algorithm contains distinct numbers. Since the sorting algorithm depends only on the relative order of the numbers in the input array and not their individual values, therefore we can associate to each input array having elements a permutation of .

Let denote the set of all permutations of . We assume that input arrays of size are permutations in the set with uniform probability distribution (each permutation occurring with probability   .)

Let be the number of permutations in requiring a total of comparisons to sort by the quick sort algorithm. Define th factorial moment of the number of comparisons by



We wish to calculate the following important result using the singularity analysis of certain generating functions appearing in [flajolet]

Theorem 1.1 ([bworld]).

For integers we have


where is the Euler’s constant.

Note that the th moment of number of comparisons admits the same asymptotic expansion as since it is just a linear combination of th factorial moments for .

2. The Calculation

We start be defining the probability generating function:

Theorem 2.1.





We assume that the first partitioning stage requires comparisons (for some other variants this might be which would result in the same asymptotic expression).

Fix some such that . Let denote the set of all permutations in having the pivot element equal to .

Each element , after the partitioning procedure executed on it, produces a pair where and denote the permutations associated with the sub arrays of sizes and obtained after the partitioning procedure is applied on , respectively.

We further assume that the partitioning method preserves equally likely distribution on produced permutations, that is, every pair in should get produced from partitioning of the same number of permutations in , that is, [hennequin]. Thus we can write


Multiplying equation (2.3) by and dividing by we get

after which summing on gives us equation (2.1). ∎

Now consider the double generating function defined by

Corollary 2.2.

We have




From equation (2.1) we have

Equation (2.6) follows from the fact that . ∎

Now notice that


The generating functions of are


Using Taylor’s formula and equation (2.7) we can write

Theorem 2.3.

For integer we have


Using Taylor’s theorem we can write

which on substituting gives


Now substituting equation (2.9) in equation (2.5) gives:

Now comparing coefficients on both sides of the equation gives

Notation: In the following let Further let be an unspecified linear combination of terms of the form where are integers with either and is arbitrary, or and .

Corollary 2.4.

For integers we have


where .


We prove this by induction on . The base case when is trivial since . Now assume that the assertion is true for all integers . First observe that the equation (2.10) is the following linear differential equation:




Solving the linear differential equation (2.13) gives us


In the following calculation we quite frequently use the fact that the derivatives of


Specially for we have

After equation (2.14) we have

Thereafter equation (2.15) gives

where to deduce the last step we used the identity and to deduce the second last step we used integration by parts. ∎

Proof of Theorem 1.1.

We would use the following result to conclude the assertion:

Theorem 2.5 (Flajolet and Odlyzko [flajolet]).



where is a positive integer and is a non-negative integer. The coefficient of in , denoted , admits the asymptotic expansion



and is the gamma function.

We can use the above result to conclude that


Here we used the result where is the digamma function [digamma]. Now we can conclude our result after equation (2.12). ∎


Comments 0
Request Comment
You are adding the first comment!
How to quickly get a good reply:
  • Give credit where it’s due by listing out the positive aspects of a paper before getting into which changes should be made.
  • Be specific in your critique, and provide supporting evidence with appropriate references to substantiate general statements.
  • Your comment should inspire ideas to flow and help the author improves the paper.

The better we are at sharing our knowledge with each other, the faster we move forward.
The feedback must be of minimum 40 characters and the title a minimum of 5 characters
Add comment
Loading ...
This is a comment super asjknd jkasnjk adsnkj
The feedback must be of minumum 40 characters
The feedback must be of minumum 40 characters

You are asking your first question!
How to quickly get a good answer:
  • Keep your question short and to the point
  • Check for grammar or spelling errors.
  • Phrase it like a question
Test description