Question
Generalize the median-finding algorithm to find the $k$ th largest item in a set of $n$ items for any given value of $k$. Prove that your resulting algorithm is correct, and bound its running time.
Step 1
First, we can use the QuickSelect algorithm, which is an efficient in-place variation of the QuickSort algorithm. It works by selecting a 'pivot' element from the array and partitioning the other elements into two groups - those less than the pivot and those Show more…
Show all steps
Your feedback will help us improve your experience
Narayan Hari and 60 other educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Given an unsorted array, A, of integers and an integer k, write a recursive algorithm for rearranging the elements in A so that all elements less than or equal to k come before any elements larger than k. What is the running time of your algorithm on an array of n values?
Give an $O(n \lg k)$ -time algorithm to merge $k$ sorted lists into one sorted list, where $n$ is the total number of elements in all the input lists. (Hint: Use a minheap for $k$ -way merging.
Heapsort
Priority queues
Describe an algorithm that produces the maximum, median, mean, and minimum of a set of three integers. (The median of a set of integers is the middle element in the list when these integers are listed in order of increasing size. The mean of a set of integers is the sum of the integers divided by the number of integers in the set.)
Algorithms
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD