Without the memory constraint, you just keep a minheap heap with the k 
largest elements. For every new number, if the heap is not full, add the 
number. Otherwise compare it to the smallest item in the heap, and if it is 
larger replace that item with the new one and downheap.

The memory constraint makes no sense. For example, if K=1, you must 
remember the largest number you have seen using zero memory. If I give you 
one 32-bit number, and you later give it back to me, you must have used 32 
bits of storage to keep that number. Or are you distinguishing between disk 
storage and memory?

Don

On Thursday, August 8, 2013 1:02:08 AM UTC-4, payel roy wrote:
>
> There is a stream of numbers coming in and you have to find K largest 
> numbers out of the numbers received so far at any given time. Next problem 
> is that a constraint is added. memory is limited to m. m < k. How would you 
> achieve the goal still.
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to