ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Hash Table]
    개발/자료구조 2022. 10. 5. 14:12

    A hash table (often called a hash map) is a data structure that maps keys to values. Hash tables combine lookup, insert, and delete operations in an efficient way. The key is sent to a hash function that performs arithmetic operations on it. The result (called the hash value or hash) is an index of the key-value pair.

    Let a hash function H(x) maps the value 

    at the index x%10 in an Array. For example if the list of values is [11,12,13,14,15] it will be stored at positions {1,2,3,4,5} in the array or Hash table respectively.

     

    언제사용할까? 

    In terms of time complexity, the operation is 0(1). On average, a hash table lookup is more efficient than other table lookup data structures. Some common uses of hash tables are:

    • Database indexing
    • Caches
    • Unique data representation
    • Lookup in an unsorted array
    • Lookup in sorted array using binary search

     

    Hash tables vs. trees

    Hashing and trees perform similar jobs, but various factors in your program determine when to use one over the other.

    Trees are more useful when an application needs to order data in a specific sequence. Hash tables are the smarter choice for randomly sorted data due to its key-value pair organization.

    Hash tables can perform in constant time, while trees usually work in O(log n). In the worst-case scenario, the performance of hash tables can be as low as O(n). An AVL tree, however, would maintain O(log n) in the worst case.

    An efficient hash table requires a hash function to distribute keys. A tree is simpler, since it accesses extra space only when needed and does not require a hash function. 

     

     

    '개발 > 자료구조' 카테고리의 다른 글

    [Big O]  (0) 2022.06.20
Designed by Tistory.