# Lecture 10: Analysis of Quicksort

This lecture provides an analysis of quicksort and utilizes generating functions to analyze the expected number
of comparisons. A recurrence relation for the expected number of comparisons is derived under the assumption that
the input elements are distinct and that each of the possible orderings are equally likely to occur. First the
recurrence relation is solved using rsolve and then a functional equation is derived for the generating function.
The functional equation is a differential equation and this equation is solved using dsolve.

### Background Material

- Sorting algorithms.
- Recursion and recurrence relations.
- Generating functions.

### Reading

Review the material on generating functions in
Also study Maple's dsolve command.
### Topics

- Quicksort algorithm.
- Empirical study of the number of comparisons used by quicksort.
- Recurrence relation for the maximum and expected number of comparisons.
- Generating function for the expected number of comparisons.

### Maple worksheets and programs and other resources

- quicksort.mw - Maple worksheet on generating functions.
computation

### Assignments

Created: Nov. 4, 2006 by jjohnson@cs.drexel.edu