Hash Table is a data structure that maps keys to values using a hash function for fast access.
Key Characteristics:
Hash Function: A hash function is a mathematical function that converts input keys into array indices. It takes a key of any size and produces a fixed-size integer that determines where the key-value pair will be stored. A good hash function should distribute keys uniformly across the table to minimize collisions and maintain fast access times.
Hash Calculation Example: For string "Age" with table size 7:
Step 1: Sum ASCII values: A(65) + g(103) + e(101) = 269
Step 2: Apply modulo: 269 % 7 = 3
Therefore, hash("Age") = 3, so "Age" is stored in bucket 3.
Operation | Average | Worst |
---|---|---|
Insert | O(1) | O(n) |
Search | O(1) | O(n) |
Delete | O(1) | O(n) |
Component | Space |
---|---|
Table Storage | O(n) |
Chain Storage | O(k) |