Find the kth min/max out of n numbers,
1) max heap, heap size k, O(nlogk)
2) 2^32 bit vector, use the value of integer as index to set bit vector, then the indexes of max k set bits are max k integers, O(n)
3) selection algorithm to find kth number then scan the array again to find the value smaller than this number O(n)
Showing posts with label max heap. Show all posts
Showing posts with label max heap. Show all posts
Dec 26, 2008
Subscribe to:
Posts (Atom)