Dictionary Abstract Data Types
Another Solution
- Can do better with Hash Tables in \(O(1)\) expected time, \(O(n+m)\) space; where m is the table size
An example
- Let
keys
be the student ids of students registered in class CLS201; eg.2022CS10110
. - There are \(100\) students in the class, so we create a hash-table of size say 100.
- Hash function
hash()
is say, the last two digits of the student-id. - So, now,
2022CS10110
goes to location10
in the hash-table.
Multiply-Add-Divide (MAD)
This technique is used to create pseudo-unique hash values.
It is also used in pseudo random number generators
The method is as follows:
\[ \text{hash}(k) = |a\cdot k + b|\ \text{mod}\ N\]
Collisions
Methods to resolve collisions
- Chaining
- Open Addressing:
- Linear Probing
- Double Hashing
Linear Probing
1 2 3 4 5 6 7 8 9 10 11 12 |
|