java - What is the best way to get a sorted list (of finite length) from a large set of input -


So assume that I have 100 million comparative as the streaming input and I output it I want to do the top 100 of that input (in order - which is trivial if i can get the top 100) I'm assuming that any kind of insertion sort will be the best, but what is the best way to accomplish this (if this is also the best way)?

The obstacles are that you definitely see every thing, one at a time (and I definitely can not set the whole set in memory).

I was thinking of two possible solutions:

1) A simple linked list. So as the first 100 objects come in, they will be sorted (O (n) time - but n = 100). Then after coming into the form of each other, it will be inserted correctly (then O (n), n = 100, time), and if it is inserted, then it will remove the tail (otherwise the linked list is unchanged) If it is higher than maximum value).

2) Use a heap. I think the size of the pile can be left to the root node (above the heap) to put in the heap if the size of the pile is above my maximum number element (100 in my case). It should mean o (LG) runtime, right? Since the entry of the element and the removal of the root is both (LG), right?

Is there a good library for stacks in Java? I really do not want to codify my heap framework.

ps

If you are wondering why I am doing this, this fashion is for football purpose. I have a program that can be used by the players under the barrier of a salar caps Finds the maximum projection point of the set (this is a cruel force algorithm). In fact this is another question, which is the way to solve a loose problem where you should have a certain number of different types of items (i.e. 1 qb, 3w, 2 rb, 1 TE, 1K, and 1 defense).

That's why I have a large number (1,234) team that gives a minimum point of points, but now I am trying to find a group of groups with wide range of different players I think It is appropriate to solve a group of three teams (choose through Brute force): 1,234 3 = 312,419,184 (which will take about an hour and a half hour to process my calculation). I can see once in each team as a player, so calculates a group of team's variance (the value is low as the group of variance of the team).

If you are adding what you are adding, you can use it.

  Public stable & lt; T & gt; SortedSet & LT; T & gt; Top value (final end n, final comparison & lt; T & gt; comparator) {New tree sheet & lt; T & gt; (Comparator) {@ Override Public Boolean Aid (TT) {// Size is less than N, just try adding it if (super.size ()   

or if the type is already comparative

  public stable  return) super.add (t); T before = super.first (); // If it is smaller than before, discard it. If (t.compareTo (first) & lt; = 0) return false; // otherwise try adding it to super.remove (first); Super.add (t); Back true; }}; }   

Just add all values ​​to this set and it will contain only the n values, each time you leave the smallest one.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -