Hashes
π Introduction
π― What Is a Hash Table?
Core Concept
# Simplified concept
def simple_hash_table():
# Array of buckets
buckets = [None] * 10
# Insert: hash key to find bucket
key = "alice"
index = hash(key) % len(buckets)
buckets[index] = ("alice", 42)
# Lookup: hash to find bucket
index = hash("alice") % len(buckets)
return buckets[index] # ("alice", 42)Time Complexity
Operation
Average
Worst
π§ Hash Functions
Python's Built-in Hash
Implementing Hash Functions
π₯ Collision Resolution
Strategy 1: Chaining
Strategy 2: Open Addressing
Probing Strategies
π Python Dict Internals
Key Features
Dict Comprehension and Methods
DefaultDict and Counter
π Sets
π Common Hash Table Problems
Two Sum
Group Anagrams
Longest Consecutive Sequence
Subarray Sum Equals K
LRU Cache
Valid Sudoku
π Practice Exercises
Exercise 1: First Unique Character
Exercise 2: Isomorphic Strings
Exercise 3: Design HashMap
π Key Takeaways
π What's Next?
π References
Last updated