Podcast
Questions and Answers
What is the optimal condition for division hashing to work best?
What is the optimal condition for division hashing to work best?
What is the purpose of folding in hash functions?
What is the purpose of folding in hash functions?
In shift folding, how are the parts of the key combined?
In shift folding, how are the parts of the key combined?
What is the advantage of the mid-square function?
What is the advantage of the mid-square function?
Signup and view all the answers
Why can hash functions be combined?
Why can hash functions be combined?
Signup and view all the answers
How are strings hashed?
How are strings hashed?
Signup and view all the answers
What is the range of ASCII codes used for hashing?
What is the range of ASCII codes used for hashing?
Signup and view all the answers
What is the purpose of the hash function in the code snippet?
What is the purpose of the hash function in the code snippet?
Signup and view all the answers
What operation is used to combine the ASCII codes in the hash function?
What operation is used to combine the ASCII codes in the hash function?
Signup and view all the answers
What is the result of the hash function in the code snippet?
What is the result of the hash function in the code snippet?
Signup and view all the answers
Study Notes
Hashing
- Average and worst-case complexity of searching, inserting, and deleting in unsorted arrays, sorted arrays, unsorted linked lists, sorted linked lists, skip lists, binary search trees (BST), and B-Trees.
Hash Functions
- Basic idea: save items in a key-indexed table where the index is a function of the key.
- Properties of a good hash function:
- Easy to compute
- Each index is equally likely to be generated for each key
- A perfect hash function assigns a unique index to each key
Types of Hash Functions
Extraction
- Use a selection of digits as the key
- Choose the part of the key that is least likely to repeat
Division Hashing
- Hash function:
hash(K) = K % T
whereT
is the size of the hash table - Works best when
T
is a large prime number - Alternatively:
hash(K) = (K % p) % T
wherep
is a prime number greater thanT
Folding
- Designed to increase variability of hash codes
- Split the key into equal parts and combine them using a simple operation like addition
- Apply division hashing to restrict the index to the desired range
- Examples: shift folding and boundary folding
Mid-Square Function
- Square the key
- Use the middle section of a desired length as the hash value
- Advantage: the entire key is used, producing more variation
- Can be combined with other hash functions like folding
Hashing Strings
- Use ASCII codes to hash strings
- Methods:
- Concatenate ASCII codes and apply division hashing
- Add ASCII values and apply division hashing
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
This quiz covers the concepts of hashing, data structures, and their complexities in terms of search, insert, and delete operations. Learn about the average and worst-case scenarios for unsorted arrays, sorted arrays, linked lists, skip lists, BST, and B-Trees.