Seven search algorithms

1. Sequential search:

Success time complexity O((n+1)/2) , failure: O(n) [Search in sequential storage or chain storage]

2. Binary search:

The search for half, must be in order, the average time complexity is O(log2n), and the failure is O(log2(n+1))

3. Interpolation search:

In the case of large table length and uniform data distribution, interpolation search is better than binary search. Interpolation is divided into 1/4, 1/5, etc., not necessarily in half. The time complexity of success and failure is O(log2(log2n))

4. Hash lookup (hash lookup):

A function (hash function, also called hash function) can be designed so that the keyword key of each element value corresponds to a function value (ie, an array subscript), so this array unit is used to store the element value; [It may appear that for different elements, the same function value is calculated, thus resulting in a "conflict"]

Hash tables have two major characteristics: direct addressing and conflict resolution.

  Algorithm flow:

  1) Construct a hash table with the given hash function;
  2) Solve the address conflict according to the selected conflict handling method;
    Common conflict resolution methods: zipper method and linear detection method.
  3) Perform a hash lookup on the basis of the hash table.
Hash tables are a classic example of the trade-off between time and space. If there are no memory constraints, then the key can be directly used as the index of the array. Then all the search time complexity is O(1); if there is no time limit, then we can use an unordered array and do a sequential search, which requires very little memory. Hash tables use a modest amount of time and space to find a balance between these two extremes. It is only necessary to adjust the hash function algorithm to make trade-offs in time and space.
Simplex lookup complexity: For a conflict-free Hash table, the lookup complexity is O(1) (note that we need to build the corresponding Hash table before lookup).
Hash is a typical space-for -time algorithm.

5、BST

6. Red-black tree

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325078726&siteId=291194637