Showing posts with label Heap. Show all posts
Showing posts with label Heap. Show all posts

Saturday, February 21, 2009

find the k largest or smallest numbers from a set of n numbers

3. How do you find the k largest or smallest numbers from a set of n numbers

Solution:

Build a min/max heap of size K from the available set.

Time complexity: n Log K