c++ - How do I get a O(log n) when I want to sort according to two keys? -


I have a bunch of nodes sorted alphabetically according to the data in the red-black tree.

  Structure node {int counter = 1; String data = nullptr; int red = 0; };   

I have used a balanced binary tree because it has a big o (log n).

The counter increases for the nodes, if I try to insert the node, the data matches any child, and / or the root (and the node is not included).

I probably want to print like the top n we say 10) the nodes are ranked by the counter in the descending order (at the very least). But since the nodes are sorted alphabetically by statistics and do not have a counter, the best scenario is to use the O (n), worst position, selection or sequential search to search through a canceled list. I can think of doing

I should be a big O (N + Log N), which is essentially the big O (N) - I was hoping to achieve something faster.

My question is how can I achieve Oi, that is, anything faster than O (N)?

By keeping data in a binary tree sorted by data in an array There is no specific order in relation to queries based on count , so you can not do anything better than linear for a single query. If you plan to execute the query multiple times, then it may have been ordered by an counter for an alternative structure. If you need to give support to everyone then the query for the top 10 binary stack will be great if you only plan to do some inquiries, you can not improve performance very much.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -