13 Hashing
13 Hashing
Chapter 9
Searching and Hashing Algorithms
Hashing
• Algorithm of order one (on average)
• Requires data to be specially organized
– Hash table
• Helps organize data
• Stored in an array
• Denoted by HT
– Hash function
• Arithmetic function denoted by h
• Applied to key X
• Compute h(X): read as h of X
• h(X) gives address of the item
• Overflow
– No longer a concern
• Data stored in linked lists
• Memory space to store data allocated dynamically
– Hash table size
• No longer needs to be greater than number of items
– Hash table less than the number of items
• Some linked lists contain more than one item
• Good hash function has average linked list length still
small (search is efficient)
• Advantages of chaining
– Item insertion and deletion: straightforward
– Efficient hash function
• Few keys hashed to same home position
• Short linked list (on average)
– Shorter search length
• If item size is large
– Saves a considerable amount of space
• Load factor
– Parameter α