Meanings of least Heap/hash table/binary tree/balanced binary tree/red/black tree (under what conditions)
The data structure of the contact heap is described in sorting. The space complexity O (1), the time complexity O (nlogn ), however, in practice, it is better to sort quickly (it seems that fast sorting can better utilize hardware features ). The significance of heap lies in: finding the Maximum/minimum values as quickly as possible, and inserting a value in the Heap Structure to reconstruct the heap structure, the maximum/lowest value is removed and the time complexity of the heap structure is O (logn), while that of other methods is O (n ). in heap practice, sorting is not used. It is mainly used in scheduling algorithms, such as priority scheduling, the highest priority, the time-driven, and the least time/the longest wait, divided into the maximum Heap/minimum heap.
Hash Tables can locate the search objects in O (1) time, but in fact, if the input set is uncertain, a large number of conflicts may occur. Although there are many good hash functions, however, with the random input, a large number of conflicts are inevitable, and the worst case may occur. Therefore, if the hash table is used to determine the input set (that is, only query operations will be performed later), select the appropriate function and the method for resolving the conflict (perfect hash) search can be completed within O (1) Time (with proof, do not understand ).
The binary tree supports dynamic insertion and search to ensure that the operation is at O (height) time. This is the work that cannot be completed by the hash table and is dynamic. However, a binary tree may contain worst-case. If the input sequence is sorted, the time complexity is O (n)
The balanced binary tree/red/black tree aims to ensure that the time complexity of the search is within the O (logn) range.
Therefore, if the input is combined with the query, you can consider using a hash table. If the input set is not sure, you need to use a balanced binary/red/black tree to ensure maximum efficiency.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/javatalk/archive/2007/05/15/1609555.aspx