25 - Hashing
452 words
2 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# 25 - Hashing ## 🎯 Learning Objectives After reading this topic, you will be able to: - Explain static hashing and its overflow problem - Describe extendible (dynamic) hashing - Understand hash function properties - Explain bitmap indices ## 📖 Core Content ### 25.1 Static Hashing A **hash function** $h$ maps sear...

25 - Hashing
🎯 Learning Objectives
After reading this topic, you will be able to:
- Explain static hashing and its overflow problem
- Describe extendible (dynamic) hashing
- Understand hash function properties
- Explain bitmap indices
📖 Core Content
25.1 Static Hashing
A hash function h maps search keys to buckets (disk blocks containing records).
Properties of a good hash function:
- Uniform: Distributes keys evenly across buckets
- Deterministic: Same key → same hash
- Fast: Low computation cost Collision: Two different keys map to the same bucket.
25.2 Handling Overflow
When a bucket is full, use overflow chaining:
- Add an overflow block linked to the original bucket
- Search must scan both the primary and overflow blocks Solution: Increase number of buckets (rehash).
25.3 Dynamic (Extendible) Hashing
Extendible hashing grows/shrinks dynamically without rehashing all data.
Key ideas:
- Use a directory of pointers to buckets
- Use i bits of the hash to index the directory
- When a bucket overflows, split it and double the directory (when needed) Example:
- Start with i=1 (directory size = 21=2), 2 buckets
- Hash keys: 0→bucket0, 1→bucket1
- If bucket0 overflows, split it: now keys ending in 00 go to bucket00, keys ending in 01 go to bucket01
- If needed, double directory (i=2, directory size = 4)
25.4 Bitmap Indices
Bitmap index: For each attribute value, create a bit vector of length = number of records.
Example:
| Record | Gender |
|---|---|
| 1 | M |
| 2 | F |
| 3 | M |
Gender='M' bitmap: 101 Gender='F' bitmap: 010
Size: m×n bits (m = number of distinct values, n = number of records).
Best for: Low-cardinality attributes (gender, status, category), data warehousing.
📝 Practice Questions
Q1. What properties should a good hash function have?
AnswerUniform distribution, deterministic (same key → same hash), fast computation, ideally maps same number of keys to each bucket regardless of actual data distribution.
Q2. What is the advantage of extendible hashing over static hashing?
AnswerExtendible hashing grows dynamically without rehashing all data. It only splits overflowing buckets and doubles the directory when needed. Static hashing requires periodic rehashing of the entire file.
Q3. When are bitmap indices most useful?
AnswerBitmap indices excel for low-cardinality attributes (few distinct values) such as gender, status codes, or boolean flags. They're especially effective in data warehousing for complex boolean queries across multiple dimensions.
🔗 Cross-References
- Previous Topic: 24 - B+ Tree Index
- Next Topic: 26 - Transactions & ACID
- Textbook: Chapter 11 (Indexing and Hashing) Join Discord Previous24 - B+ Tree IndexNext26 - Transactions & ACID