Cover of Introduction To Algorithms by Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, Clifford Stein - Business and Economics Book

From "Introduction To Algorithms"

Author: Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, Clifford Stein
Publisher: MIT Press
Year: 2001
Category: Computers

🎧 Free Preview Complete

You've listened to your free 10-minute preview.
Sign up free to continue listening to the full summary.

🎧 Listen to Summary

Free 10-min Preview
0:00
Speed:
10:00 free remaining
Chapter 2: II Sorting and Order Statistics
Key Insight 9 from this chapter

Advanced Linear-Time Selection Algorithms

Key Insight

The general selection problem, which aims to find the 'i'th smallest element, can be solved in expected linear time using the `RANDOMIZED-SELECT` algorithm. This algorithm is structured like quicksort but critically recurses on only one side of the partition. It employs the `RANDOMIZED-PARTITION` procedure to select a pivot. While its worst-case running time is Theta(n^2) (e.g., if partitioning consistently yields the largest remaining element), its randomized nature ensures an expected linear running time of Theta(n) across all inputs, assuming distinct elements.

For a guaranteed worst-case linear time solution, the `SELECT` algorithm is used. This deterministic algorithm ensures a 'good split' by carefully choosing a pivot element. It first divides the 'n' elements into 'floor(n/5)' groups of 5, plus a remainder group. Then, it finds the median of each of these groups by insertion sorting them. The algorithm then recursively calls `SELECT` to find the median of these medians (the 'median-of-medians'), which serves as the partitioning pivot 'x'.

By using the median-of-medians 'x' as the pivot, `SELECT` guarantees that a significant fraction of elements are smaller than 'x' and a significant fraction are larger. Specifically, at least '3n/10 - 6' elements are guaranteed to be less than 'x' and '3n/10 - 6' elements greater than 'x'. This ensures that the recursive call in the worst case is made on a subarray of size at most '7n/10 + 6'. This leads to a recurrence relation 'T(n) <= T(ceil(n/5)) + T(7n/10 + 6) + O(n)', which, by substitution, proves a worst-case running time of O(n). These selection algorithms are not comparison sorts, allowing them to bypass the Omega(n log n) lower bound applicable to sorting.

📚 Continue Your Learning Journey — No Payment Required

Access the complete Introduction To Algorithms summary with audio narration, key takeaways, and actionable insights from Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, Clifford Stein.