[algogeeks] How to store largest N values efficiently

2011-07-11 Thread John Reid
I have a procedure that generates N x M values sequentially. I want to store the N largest ones and discard the others. Obviously I can store all the values in a vector, sort it when it is full and then choose the top N values. Is there a more efficient way using a data structure that just

Re: [algogeeks] How to store largest N values efficiently

2011-07-11 Thread abhijith reddy
Wouldn't a heap be ideal for this ? On Mon, Jul 11, 2011 at 3:35 PM, John Reid j.r...@mail.cryst.bbk.ac.ukwrote: I have a procedure that generates N x M values sequentially. I want to store the N largest ones and discard the others. Obviously I can store all the values in a vector, sort it

Re: [algogeeks] How to store largest N values efficiently

2011-07-11 Thread saurabh singh
Similar to selection searching problem. On Mon, Jul 11, 2011 at 4:37 PM, abhijith reddy abhijith200...@gmail.comwrote: Wouldn't a heap be ideal for this ? On Mon, Jul 11, 2011 at 3:35 PM, John Reid j.r...@mail.cryst.bbk.ac.ukwrote: I have a procedure that generates N x M values