{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# feb2 - Illinois Institute of Technology Department of...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Illinois Institute of Technology Department of Computer Science Lecture 4: February 2, 2009 CS 430 Introduction to Algorithms Spring Semester, 2009 1 Quicksort Quicksort is likely the most commonly used algorithm for sorting internally. Its analysis is also of particular interest because its performance on average is asymptotically faster than its worst-case performance. Although there are many variants, the basic form of the algorithm selects the first element of the array and partitions the array around the value of that element: that is, it divides the array into two sections, one consisting of all elements smaller than the first element and the second consisting of all elements larger than the first element. It then sorts each partition recursively. 1 To analyze the quicksort algorithm, we must ask how it behaves in the best case, in the average case, and in the worst case. The best case occurs when all of the partitions are perfectly balanced—that is, when the array is partitioned evenly in each recursive call. The worst case occurs when the input array is already sorted, as in that case the partitions are all unbalanced. What are we counting in our analyses? In most sorting algorithms, including quicksort, the running time is proportional to the number of comparisons of pairs of elements. To simplify matters, then, we only count comparisons of pairs of elements. In general, what is the form of the recurrence we will be using? In an array of size n , partitioning can be accomplished in n- 1 comparisons. If partitioning yields one subarray of size k and one subarray of size n- 1- k , the general recurrence is of the form c ( n ) = n- 1 + c ( k ) + c ( n- 1- k ) 1.1 Best-case analysis In the best case, the partitions are balanced at all levels of the recursion. Thus, in the general form above, k = § n- 1 2 ¨ . This yields the recurrence c (...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

feb2 - Illinois Institute of Technology Department of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online