I want to know the best way to sort a long list of strings for the efficiency of time and space. I prefer time efficiency on space efficiency.
The string can be numeric, alpha, alphanumeric, etc. I am not interested in this kind of behavior like sorting alphanumeric sort v / s alphabetically
Below are some of the ways that I can think of.
-
Using the pre-code: .Net framework's arrays.Sort () function. I think the way it works is that the hashodode is calculated for the string and the string is inserted in the proper position using binary search.
-
Use the database (ex: MS-sql). I have not done this, I do not know how effective it will be.
-
Using a tree such as the prefix tree data structure, to trim all the triangular nodes of the three-tree is required to use DFS (deep search before) - o (| V | | | E |) Time (searches the time of O (L) where the length of the string is to compare l).
Any other methods or data structures?
You say that you have a database, and presumably the strings are stored in the database. You should get the database to work for yourself. It may be able to take advantage of an index, and therefore really does not need to sort the list, rather it should be read from the index in the ordered order.
If there is no index then still the database will help you. If you only get the first K rows for some small continuous numbers, for example 100. When you use the ORDER BY from the serial limit, it allows the SQL server to use a special optimization That time (n) runs in linear time rather than n log)
If your string is not already present in the database, then you should use the features provided by it. I think it is not possible that you will be able to write a custom code that will be faster than the default sort.
Comments
Post a Comment