Quiz 2

25 - Hashing

452 words
2 min read
Python Week 1: the first filter for runtime behavior
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 hh maps search keys to buckets (disk blocks containing records).
h(K)=bucket numberh(K) = \text{bucket number}
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 ii bits of the hash to index the directory
  • When a bucket overflows, split it and double the directory (when needed) Example:
  1. Start with i=1i=1 (directory size = 21=22^1 = 2), 2 buckets
  2. Hash keys: 0→bucket0, 1→bucket1
  3. If bucket0 overflows, split it: now keys ending in 00 go to bucket00, keys ending in 01 go to bucket01
  4. If needed, double directory (i=2i=2, directory size = 4)

25.4 Bitmap Indices

Bitmap index: For each attribute value, create a bit vector of length = number of records. Example:
RecordGender
1M
2F
3M
Gender='M' bitmap: 101 Gender='F' bitmap: 010 Size: m×nm \times 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?

Answer
Uniform 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?

Answer
Extendible 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?

Answer
Bitmap 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

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.