Speed:
Quadratic Probing Hash Table
Average: O(1)Worst: O(n)Space: O(n)
🔍How Quadratic Probing Works
Quadratic Probing is a collision resolution technique for hash tables that uses a quadratic function to find the next available slot when a collision occurs. Instead of checking consecutive slots (linear probing), it checks slots at quadratic intervals.
The probing sequence follows the formula:
h(k, i) = (h(k) + i²) mod m
where k = key, i = probe number (0, 1, 2, ...), m = table size
- Collision occurs: Use quadratic sequence: +0, +1, +4, +9, +16, ...
- Better clustering: Avoids primary clustering of linear probing
- Load factor: Keep below 0.7 for optimal performance
- Table size: Should be prime to ensure good distribution
💻Implementation
📊Performance Analysis
Time Complexity
- • Average Insert: O(1)
- • Average Search: O(1)
- • Average Delete: O(1)
- • Worst case: O(n) for all operations
Key Properties
- • Space: O(n) for table storage
- • Load factor: α = n/m should be < 0.7
- • Clustering: Reduces primary clustering
- • Cache performance: Better than chaining
✅ Advantages
- • Better than linear probing: Reduces primary clustering
- • Cache-friendly: Better memory locality than chaining
- • Simple implementation: No extra data structures needed
- • Memory efficient: No pointer overhead
- • Good performance: When load factor is controlled
❌ Disadvantages
- • Secondary clustering: Keys with same hash value cluster
- • Limited load factor: Performance degrades after 70% full
- • Deletion complexity: Requires tombstone mechanism
- • Table size constraints: Must be prime for optimal performance
- • Probing may fail: Cannot guarantee finding slot in full table