# 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.

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
{"ft_lang_label":"__label__en","ft_lang_prob":0.8447884,"math_prob":0.96756256,"size":1183,"snap":"2021-31-2021-39","text_gpt3_token_len":235,"char_repetition_ratio":0.14419,"word_repetition_ratio":0.035714287,"special_character_ratio":0.17666948,"punctuation_ratio":0.10695187,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9882784,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-30T10:45:31Z\",\"WARC-Record-ID\":\"<urn:uuid:c104cc2d-fee8-4a18-b1a9-4f208a9946cc>\",\"Content-Length\":\"2484\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ca989121-9294-4be2-86df-a2c7ed8509c2>\",\"WARC-Concurrent-To\":\"<urn:uuid:58ce60bc-5abd-4246-8563-635d1072d28f>\",\"WARC-IP-Address\":\"129.25.203.108\",\"WARC-Target-URI\":\"https://www.cs.drexel.edu/~jjohnson/2006-07/fall/cs300/lectures/lec10.html\",\"WARC-Payload-Digest\":\"sha1:LLYSCTNH4QOG3Q7SA3LRDN5MJVDKNT4T\",\"WARC-Block-Digest\":\"sha1:PBTASFXNQPCWEQVXFINZWMOW75F3XH3G\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153966.52_warc_CC-MAIN-20210730091645-20210730121645-00485.warc.gz\"}"}