Hash Tables - Open Addressing
     
Hash Function:    Collision Strategy
   Step-by-Step Animation   Animation Speed 
Elaboration:
?
Open Addressing: It resolves the hash collision issue by searching through the array until reaching a valid location. Each element in the array is either empty or stores one piece of data. The animation shows searching strategies:
1. Linear Probing: Use a linear function (y(i) = c · i, c is constant) to search for a valid location. Our animation uses the constant value 1 for c.
hi = (Hash(key) + c · i) % tableSize
2. Quadratic Probing: Use a quadratic function (y(i) = c1i + c2i2, c1 and c2 are constant) to search for a valid location. The animation uses the constant values 0 and 1 for c1 and c2 respectively.
hi = (Hash(key) + c1i + c2i2) % tableSize
3. Double Hashing: Use a second hash function to search for a valid location.
hi = (Hash1(key) + Hash2(key) · i ) % tableSize
Animation Supported Hash Functions:
1. DJB2: Please refer here
2. ASCII: Return the sum of ASCII values of each character given a string.
3. Manually Enter: This is not a hash function. But it helps you insert an element to a specific location flexibly without knowing the behavior of the hash function.
API explanation: A good hash function helps the performance of hash table operations because the collision happens in less time.
1. Insert: Insert a new element onto the hash table - average O(1), worse case O(n)
2. Delete: Delete the given element if it's found - average O(1), worse case O(n)
3. Find Find the given element - average O(1), worse case O(n)
A little math about modulo operation:
(a + b) % c = (a % c + b % c) % c
哈希表定义:哈希表(又名散列表),是根据关键码值(Key value)而直接进行访问的数据结构。它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。其存放记录的数组叫做哈希表。
Open Addressing: 对于需要动态维护的哈希表,关键码在查询过程中会出现地址的冲突这一点是无法避免的。开放定址法就是解决冲突的方法之一。此算法将所有的元素都存储在散列表中,要系统的检查所有的表项,直到找到所需的元素,或者所需的不在表中。用开放寻址法来插入元素,需要进行探查,直到找到空的槽来存放关键字为止。
1. Linear Probing: Use a linear function (y(i) = c · i, c is constant) to search for a valid location. Our animation uses constant value 1 for c.
hi = (Hash(key) + c · i) % tableSize
2. Quadratic Probing: Use a quadratic function (y(i) = c1i + c2i2, c1 and c2 are constant) to search for a valid location. The animation uses constant valiue 0, 1 for c1 and c2 respetively.
hi = (Hash(key) + c1i + c2i2) % tableSize
3. Double Hashing: Use a second hash function to search for a valid location.
hi = (Hash1(key) + Hash2(key) · i ) % tableSize
Animation Supported Hash Functions:
1. DJB2: Please refer here
2. ASCII: Return the sum of ASCII values of each character given a string.
3. Manually Enter: This is not a hash function. But it helps you insert an element to a specific location flexibly without knowing the behavior of the hash function.
API explanations: A good hash function helps the performance of hash table operations because the collision happens in less time.
1. Insert: Insert a new element onto the hash table - average O(1), worse case O(n)
2. Delete: Delete the given element if it's found - average O(1), worse case O(n)
3. Find Find the given element - average O(1), worse case O(n)
A little math about modulo operation:
(a + b) % c = (a % c + b % c) % c