Algorithm Diagram - Hash Table

  Hash table, also called hash table. Features: Find fast.

  The gist: Hash table implementation, collisions, and hash functions.

5.1 Hash functions

Require:

  1. The input and output of the hash function must be consistent, that is, a fixed input must correspond to a fixed output value;
  2. The input and output of the hash function are best unique, that is, ideally the mapping is unique.
    def check_voter(name):
        if voted.get(name):
            print ("kick them out")
        else:
            voted[name] = True
            print ("let them vote!")
    check_voter(name)

    The code above is just a dictionary to illustrate the usage of the hash table.

5.2 Application

  Hash tables are often used for caching, DNS resolution, etc.

5.3 Conflicts

  If two keys map to the same location, it is solved by storing a linked list.

5.4 Performance

  The hash table is O(1) on average and O(n) worst case.

  A good hash function will always have a fill factor less than 1.

Summarize:

  1. Hash tables can be created by combining hash functions and arrays
  2. A hash function that minimizes collisions should be used
  3. Hash table lookups, insertions and deletions are very fast
  4. Hash table suitable for simulating mappings
  5. Once the fill factor exceeds 0.7, it is time to adjust the length of the hash table
  6. Hash tables can be used to cache data
  7. Hash tables are great for preventing duplication

Example: Hash table, one of the data structures implemented in C language

https://blog.csdn.net/smstong/article/details/51145786

  

Guess you like

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