Dec 26, 2008

Find the kth min/max out of n numbers,

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)

No comments:

Post a Comment