hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is Pair with Given Sum
This is Two Sum as a yes/no question: does any pair add to k? Store values already seen and probe k − x before inserting x.
1, 4, 45, 6, 10, 8 and k = 16. When 10 arrives, 6 is already in the set.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Probe + insert | O(1) expected |
| Full scan | O(n) |
| Space | O(n) |
Python implementation