Largest i numbers in sorted order
Given a set of
n numbers, we wish to find thei largest in sorted order using a comparison based algorithm. Find the algorithm that implements each of the following methods with the best asymptotic worst-case running time, and analyze the running time of the algorithms in terms ofn andi .
- Sort the numbers, and list the
i largest- Build a max-priority queue from the numbers, and call `EXTRACT-MAX`
i times- Use an order-statistic algorithm to find the
i th largest number, partition around that number, and sort thei largest numbers.
Sorting
We can sort with any of the
This will take
Max-priority queue
We can build the heap linearly and then take each of the largest
This takes
Partition and sort
Let's assume we use the SELECT algorithm from the chapter. We can find the
This takes
Read full article from Problem 9.1
No comments:
Post a Comment