Answer the question
In order to leave comments, you need to log in
How to optimize selection with simultaneous sorting?
There are a large number of elements (in RAM), each of which has a certain set of tags and a weight (a number, a criterion for sorting). You must first select all the elements by 2-3 tags, and then select 10 items with the highest weight from the result.
With tags, everything seems to be simple - it's hashing. If you scatter references to elements across hash tables, then you can select all the necessary ones in almost O (1). But then, in any case, you have to sort. Is it possible to somehow optimize this sorting or get rid of it? Because every microsecond counts.
Answer the question
In order to leave comments, you need to log in
In general, it turned out that it is possible to significantly speed up the algorithm if the nature of the initial data is at least a little known.
Of course, you can always deliberately slip such data that the algorithm will not be effective. But opposition to this is beyond the scope of the question.
Heap . Build a pile 10 long as you choose. A heap can be represented very efficiently by an array, and has good implementations in almost all languages. Your task is an academic example of heap application.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question