Analysis of back-and-forth version of quicksort
Consider back-and-forth quicksort (described in hwk-6, prob 3) applied
to
values. Let
be the average number of comparisons the
algorithm uses. We know
. The partition operation
is done with exactly
comparisons. Assume that the partition
value turns out to have sorted rank (order position)
. Then we
have its location, but we still have to recursively quicksort the
smallest values and the
largest values. So, for a fixed
,
the remaining steps of quicksort take
comparisons on
average.
But the value of
is equally likely to be any integer from
to
.
So, averaging over all possible values of
, the expected number of
remaining steps of quicksort takes is
comparisons.
We claim that
for some constant
and
.
Proof by constructive induction.
Base case:
:
and
.
Induction step:
Assume it holds for all positive integers less than
.
Then