Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest data structure for inserting/sorting

I need a data structure that can insert elements and sort itself as quickly as possible. I will be inserting a lot more than sorting. Deleting is not much of a concern and nethier is space. My specific implementation will additionally store nodes in an array, so lookup will be O(1), i.e. you don't have to worry about it.

like image 235
someguy Avatar asked Sep 03 '10 11:09

someguy


People also ask

Which data structure is most efficient for sorting?

Quicksort. Quicksort is one of the most efficient sorting algorithms, and this makes of it one of the most used as well. The first thing to do is to select a pivot number, this number will separate the data, on its left are the numbers smaller than it and the greater numbers on the right.

Which data structure has the fastest insertion procedure?

Primitive data types, abstract data types, binary trees, array, B-tree, heap nd trie are some of the major data structure. Amongst these, a balanced binary tree has the fastest insertion procedure with a complexity of O(logn).

Which data structure is fastest?

The best data structure for faster searching of string is TRIE. Tries are an extremely special and useful data-structure that are based on the prefix of a string. They are used to represent the “Retrieval” of data. A Trie is a special data structure used to store strings that can be visualized like a graph.

Is it faster to insert sorted or sort after?

Sorting and inserting are the same speed.


1 Answers

If you're inserting a lot more than sorting, then it may be best to use an unsorted list/vector, and quicksort it when you need it sorted. This keeps inserts very fast. The one1 drawback is that sorting is a comparatively lengthy operation, since it's not amortized over the many inserts. If you depend on relatively constant time, this can be bad.

1 Come to think of it, there's a second drawback. If you underestimate your sort frequency, this could quickly end up being overall slower than a tree or a sorted list. If you sort after every insert, for instance, then the insert+quicksort cycle would be a bad idea.

like image 159
P Daddy Avatar answered Sep 22 '22 04:09

P Daddy