Click here to Skip to main content
15,916,188 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: find the largest 1000 values Pin
David Crow7-Nov-07 4:55
David Crow7-Nov-07 4:55 
AnswerRe: find the largest 1000 values Pin
Cyrilix7-Nov-07 13:25
Cyrilix7-Nov-07 13:25 
GeneralRe: find the largest 1000 values Pin
George_George7-Nov-07 17:01
George_George7-Nov-07 17:01 
GeneralRe: find the largest 1000 values [modified] Pin
Cyrilix7-Nov-07 18:37
Cyrilix7-Nov-07 18:37 
GeneralRe: find the largest 1000 values Pin
George_George7-Nov-07 19:15
George_George7-Nov-07 19:15 
GeneralRe: find the largest 1000 values [modified] Pin
Cyrilix7-Nov-07 19:29
Cyrilix7-Nov-07 19:29 
GeneralRe: find the largest 1000 values Pin
George_George7-Nov-07 20:09
George_George7-Nov-07 20:09 
GeneralRe: find the largest 1000 values Pin
Cyrilix7-Nov-07 20:27
Cyrilix7-Nov-07 20:27 
The MSDN documentation seems to say that the average time complexity is O(n) w.r.t. last - first, which is better than any general sorting algorithm (which should be at best O(n log n)), so because of the fact that the entire dataset does not need to be properly sorted, there may be some trick to the implementation that improves the performance, however, I don't see which context you are going to be using this in. If you do something like nth_element(start, 1000, end), I'm assuming you need to have your data structure built up so that it has every single element in a node (the example they use in the documentation is a vector). Wouldn't this mean that you'd have to get every single value and store it in memory, which from what you said, would be too large to fit in memory?

I thought about calling this on 1000 datasets of size 1 million each (for a total dataset size of 1 billion), and then having it called again on the 1000 * 1000 filtered out results, however, this does not guarantee that you get the lowest values, if your dataset is highly randomized. You may be able to implement a more complex algorithm built on nth_element() and some statistical analysis, that does "best guess" estimation as to what the nth element should be for each of the size 1 million datasets, however, from this point on, I'm only speculating as to how performance would look like. Also, I don't know what the requirements are... whether or not a best guess is good enough.
GeneralRe: find the largest 1000 values Pin
George_George7-Nov-07 20:45
George_George7-Nov-07 20:45 
GeneralRe: find the largest 1000 values Pin
Cyrilix7-Nov-07 20:53
Cyrilix7-Nov-07 20:53 
GeneralRe: find the largest 1000 values Pin
George_George7-Nov-07 21:49
George_George7-Nov-07 21:49 
GeneralRe: find the largest 1000 values Pin
Cyrilix7-Nov-07 21:52
Cyrilix7-Nov-07 21:52 
GeneralRe: find the largest 1000 values Pin
George_George7-Nov-07 22:00
George_George7-Nov-07 22:00 
GeneralRe: find the largest 1000 values Pin
Cyrilix7-Nov-07 22:46
Cyrilix7-Nov-07 22:46 
GeneralRe: find the largest 1000 values Pin
George_George8-Nov-07 3:55
George_George8-Nov-07 3:55 
AnswerRe: find the largest 1000 values Pin
George_George7-Nov-07 16:56
George_George7-Nov-07 16:56 
GeneralRe: find the largest 1000 values Pin
David Crow8-Nov-07 2:28
David Crow8-Nov-07 2:28 
GeneralRe: find the largest 1000 values Pin
George_George8-Nov-07 3:55
George_George8-Nov-07 3:55 
GeneralRe: find the largest 1000 values Pin
David Crow8-Nov-07 4:03
David Crow8-Nov-07 4:03 
GeneralRe: find the largest 1000 values Pin
George_George8-Nov-07 4:05
George_George8-Nov-07 4:05 
GeneralRe: find the largest 1000 values Pin
David Crow8-Nov-07 4:31
David Crow8-Nov-07 4:31 
GeneralRe: find the largest 1000 values Pin
George_George8-Nov-07 21:01
George_George8-Nov-07 21:01 
GeneralRe: find the largest 1000 values Pin
David Crow9-Nov-07 2:43
David Crow9-Nov-07 2:43 
GeneralRe: find the largest 1000 values Pin
George_George9-Nov-07 3:11
George_George9-Nov-07 3:11 
GeneralRe: find the largest 1000 values Pin
David Crow9-Nov-07 5:57
David Crow9-Nov-07 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.