CS5539 Data Structures and Algorithms. Lecture 19 Hashing. Reading. Watt and Brown:Chapter 12. Time Complexities. OperationKey-indexed Parallel Single BSTBST arraysortedLinked well ill arrayList balanced getO(1)O(log n)O(n)O(log n)O(n)
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
CS5539 Data Structures and Algorithms
Watt and Brown:Chapter 12
OperationKey-indexed Parallel Single BSTBST
arraysortedLinked well ill
getO(1)O(log n)O(n)O(log n)O(n)
obtain time complexity O(1) without restriction on key type
1.Create integer hash code
Derived from the value of the key
Ideally unique hash code for each key
2. Map hash code on to the index range
0..Size-1 of the table
Typically uses modulo arithmetic
index = hashcode(key) % size
. . .
. . .
Represents an empty bucket
. . .
. . .
Use alphabet position of first letter of word. (Start at 0)
Hash Table has 26 buckets
A hash function adding up the values of the characters in the key - letters are given a value using their position in the alphabetintegers are given their integer value.
Taking an table of size 10 the code S101 is converted as follows:
21 modulus 10 = 1element should be placed at bucket 1
Problem: several keys hash to the same location.
Hash(key) = (2 * int(key) modulus 10)
(2* (3+1+20)) % 10 = 48 % 10 = 8
(2*(4+15+7)) % 10 = 52 % 10 = 2
(2*(5+12+5+16+8+1+14+20) )% 10 = 162 % 10 = 2
(2*(6+18+15+7)) % 10 = 92 % 10 = 2
Any problems with this function ?
primeNumber * int(key)
(primeNumber * int(key)) % TableSize
Open-bucket hash table: where a bucket is a storage location for a single data element.
The result of transforming a key will give the home bucket.
Closed-bucket hash table: where a bucket is a storage location for a collection of data elements