GeeksforGeeks » Algorithms
Print k largest numbers
(3 posts)
[closed]
-
Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.
-
Following approaches can be used:
1) Sort the elements in descending order. Print the first k numbers of the sorted array.
Time complexity: O(nlogn)2) Build a max-heap tree and call extract-max k times
Time complexity: O(n + klogn) -
@geek4u and @Shilpi: This has been published. Please see http://geeksforgeeks.org/?p=2392.
We have added one more method that uses order statistics.
Thanks for your contribution to the portal. Keep it up!!
Topic Closed
This topic has been closed to new replies.