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)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment