An Analysis of Brent’s Insertion Method for Hash Tables
Abstract
In 1968, Richard P. Brent introduced a new way of building a hash table that, at least empirically, achieves a remarkable property: Even if the hash table is filled to 100% full, the expected time to query a random key out of those present is .
Despite the simplicity of Brent’s method, the guarantees of the method have never been formally analyzed. This is due to the subtle issue of handling spoiled randomness. The algorithm will sometimes try to use hash functions on keys that it has already probed in the past. When the algorithm does this, we cannot treat the hash function as random, because its random bits have already affected the state of the table. This issue makes Brent’s method surprisingly subtle to reason about formally.
In this note, we give a simple and formal analysis of Brent’s hash table. The analysis can be taught in a graduate randomized algorithms course, and provides a nice example of how to deal with subtle issues in a probabilistic analysis (namely, the issue of spoiled randomness).
1 Introduction
In 1968, Richard P. Brent introduced a new way of building a hash table that, at least empirically, achieves a remarkable property: Even if the hash table is filled to 100% full, the expected time to query a random key out of those present is [BRE73].
Brent’s method works as follows. Each key hashes to a probe sequence of independent and uniformly random positions in an array of size . As in a standard random probing hash table [KNU98], a query for a key simply examines the positions in order, until it finds the key.111If a key is not present, the query can complete once it encounters a free slot in the sequence. What makes Brent’s method interesting is how it performs insertions. The insertion of a key proceeds in rounds, where round tries to either insert directly in position (if the position is free) or to displace some other key from one of positions and to then move forward in its own probe sequence by positions (if that position is free). See Algorithm 1.
Brent was interested in the amortized expected query time of the hash table, which is the time to query a random key out of those present, after the hash table has been filled to be a fraction full for some parameter . Whereas most hash tables have an amortized expected query time that is a function of , Brent hypothesized that his method should have an amortized expected query time of , regardless of the parameter .
Brent’s hypothesis, although supported by both experimental and heuristical evidence [BRE73, CEL86, GM79], is surprisingly subtle to analyze formally. Despite a great deal of additional work on the topic, including numerous extensions of Brent’s technique [GM79, MAL77, LYO78, POB77], and even a survey on the topic [CM86], the basic task of analyzing Brent’s method has remained open [CM86].
In this note, we give a formal proof that Brent’s method achieves amortized expected query time .
Theorem 1.1.
Let . Suppose Brent’s method is used to insert keys into a hash table of size . Then the expected time to query a random key out of those present is . Moreover, if the hash table is not yet full, then the expected time to perform an additional insertion is .
In addition to bounding the amortized expected query time, Theorem 1.1 also obtains a tight bound on expected query time, which resolves a conjecture by Celis and Munro [CM86] that the expected insertion time is at load factors . Interestingly, our insertion time bound also offers somewhat of a counterbalance to Knuth [KNU98], who describes Brent’s method as “doing more work when inserting an item, moving records in order to reduce the expected retrieval time.” Theorem 1.1 tells us that, at least asymptotically, the insertion time for Brent’s method is the same as that for classic random probing.
The proof of Theorem 1.1 is designed to be teachable as a single lecture in a graduate Randomized Algorithms course. It serves as a good example of how to deal with subtle issues in a probabilistic analysis (namely, the issue of spoiled randomness), while also showcasing a simple and beautiful algorithm from the early data-structures literature.
In the decades since Brent’s original paper, there has been a huge body of work on how to build time- and space-efficient hash tables (see, e.g., [FNS+88, FN93, RRR03, FPS+03, DW05, DdP+06, ANS10, BKK22a, BFK+22b, BCF+23, BE23, LLY+23, LLY+24, BK24, BKZ25]), leading ultimately to the development of matching upper and lower bounds for the optimal time-space tradeoffs achievable by any abstract data structure that solves the hash table problem [BFK+22b, LLY+23, LLY+24]. For open-addressing hash tables, it is only in the last few years that we have seen examples of hash table analyses that formally achieve amortized expected query time [BKZ24, FKK24]. More than half a century after Brent’s contribution, it remains the case that his method is by far the simplest known technique for achieving the guarantee. The results in this paper show that this simple algorithm also has a relatively clean and simple analysis.
2 The Analysis
In this section, we prove Theorem 1.1. Before diving into the proof, let us take a moment to first understand why, intuitively, Brent’s method should achieve amortized expected query time .
Consider an insertion taking place when the hash table is a fraction full. In the first rounds, the insertion probes different positions to check if they are free. If we imagine that each of these probes has an probability of success, then it stands to reason that the insertion should complete after roughly rounds. By design, if the insertion completes in the -th round, for some , then it increases the sum of the query times of all elements present by exactly . This suggests that the increase to query times from an insertion at load factor is roughly . Integrating over insertions, even if we fill the hash table to 100% full, the amortized expected query time should be roughly
What makes this intuition tricky to formalize is the issue of spoiled randomness. For each key in the hash table, and each hash function , the first time that we ever probe we can think of the hash function as providing “fresh randomness”. If, at that point in time, the hash table is full, then the probe has an probability of finding a free slot. Notice, however, that for the same key , there may be many insertions that consider moving to position . After the first such attempt, we can no longer think of subsequent probes to position as examining a random slot. Rather, such probes are “wasted” on a slot that we already know to be occupied.
As a convention, for a given key and hash function , we say that is fresh for key if it has never yet been probed by any insertion, and is spoiled for key if some past insertion has already probed it. Likewise, when an insertion probes for some key and hash function , we say that the probe is fresh if is fresh for , and that the probe is spoiled otherwise. Spoiled probes are guaranteed to fail, since (unbeknownst to the current insertion) the same probe has already been performed in the past, and the slot being probed is guaranteed to be occupied.
To bound the effect of spoiled probes on the analysis, we make use of the following result, which is a standard generalization of the classic coupon-collector lemma to the case where we wish to collect only a fraction of coupons (see, e.g., [FKK24] for a simple proof).
Lemma 2.1.
Let and let . Let be independent and uniformly random positions in . Let be the smallest index such that
Then, with probability , we have .
Intuitively, the coupon-collector lemma can be used to bound the number of pairs such that is already spoiled for . It tells us that, when the hash table is full, the total number of such pairs is . This means that, for a random element in the table, is only involved in such pairs in expectation. Thus, on a given insertion, and for a given element that the insertion displaces, we only expect to incur roughly spoiled probes on that element. This basic insight is the starting point of the analysis, allowing us to prove the following lemma, which bounds the number of rounds that a given insertion takes.
Lemma 2.2.
Suppose that after inserting elements , we insert an additional element . For all , the probability that the insertion requires at least rounds is at most .
Proof.
Let denote the number of hash functions that are already spoiled for (they have already been probed by at least one past insertion). Then, by the generalized coupon-collector lemma (Lemma 2.1), with probability , we have
| (1) |
For the rest of the proof, let us condition on some fixed outcome of the first insertions such that (1) holds. The only randomness that we will use in our analysis is the randomness of the hashes for the element currently being inserted, and the randomness of fresh probes (i.e., of for hash functions and keys such that is not yet spoiled for ).
Now, consider the elements in positions that we consider displacing during the -th round of the insertion. If position is empty, then define and say as a convention that . Because are independent random hash functions (and because we have already conditioned on outcomes for for all ), the random variables are independent. Moreover, by (1), each has expected value at most for some positive constant . By Markov’s inequality, it follows that . Thus, each is independently at most with probability at least .
Recall by a Chernoff bound that, if we flip independent coins, each of which has probability at least of being heads, then with probability at least , at least of the coins are heads. Applying this to the random variables , where a coin flip corresponds to the event , we can conclude that, with probability at least
| (2) |
at least of the values are at most . Condition on this event, and label these elements by .
If any of are null (i.e., they correspond to an empty position), then the insertion will trivially succeed by the end of the -th round. Otherwise, are each elements whose hash functions have never yet been probed. The first rounds of the insertion are therefore able to make at least
fresh probes. Since , this amounts to at least fresh probes. Each of these probes independently has probability of finding a free slot, so the probability of the round failing is at most
| (3) |
Putting the pieces together, the overall probability of the insertion failing to complete after rounds is (from (1), (2), and (3)) at most
where the term comes from the probability of the coupon-collector lemma failing, the term comes from (2), and the term comes from the final step of the analysis. ∎
Proof of Theorem 1.1.
We begin by analyzing an insertion of an element that takes place when the hash table is full. By Lemma 2.2, the probability that the insertion requires at least rounds is at most . The expected number of rounds that the insertion takes is therefore , while the expected number of probes that the insertion makes is (since the -th round makes probes). To bound the insertion time, we must also include the time to calculate during each round the current hash function that the element in position is using. Because (if it is not empty) is a random element in the hash table, this is the same time as the expected time to query a random element out of those present, which we will shortly show to be . Thus the overall expected insertion time is .
Now let us consider the expected time to query a random key out of those present, after the hash table has had insertions. If the -th insertion takes rounds, then it increases the sum of the query times of all elements present by exactly . The expected sum of the query times is therefore
Since an insertion at full takes expected rounds, this is at most
The expected time to query a random key out of those present is therefore .
∎
Acknowledgments
This work was supported in part by NSF grants CCF-2542165 and CCF-2504471, and by a Jane Street grant.
References
- [ANS10] (2010) Backyard cuckoo hashing: constant worst-case operations with a succinct representation. In Proceedings of the 51st Annual IEEE Symposium on Foundations of Computer Science (FOCS), pp. 787–796. Cited by: §1.
- [BKK22a] (2022) Linear probing revisited: tombstones mark the demise of primary clustering. In 2021 IEEE 62nd Annual Symposium on Foundations of Computer Science (FOCS), pp. 1171–1182. Cited by: §1.
- [BKZ25] (2025) Optimal non-oblivious open addressing. In Proceedings of the 57th Annual ACM Symposium on Theory of Computing, pp. 268–277. Cited by: §1.
- [BCF+23] (2023) Iceberg hashing: optimizing many hash-table criteria at once. Journal of the ACM 70 (6), pp. 40:1–40:51. External Links: Document Cited by: §1.
- [BFK+22b] (2022) On the optimal time/space tradeoff for hash tables. In Proceedings of the 54th Annual ACM SIGACT Symposium on Theory of Computing (STOC), pp. 1284–1297. Cited by: §1.
- [BKZ24] (2024) Tight bounds for classical open addressing. In Proceedings of the 65th IEEE Symposium on Foundations of Computer Science (FOCS), pp. 636–657. External Links: Document Cited by: §1.
- [BE23] (2023) Dynamic dictionaries for multisets and counting filters with constant time operations. Algorithmica 85 (6), pp. 1786–1804. Cited by: §1.
- [BK24] (2024) Tight analyses of ordered and unordered linear probing. In 2024 IEEE 65th Annual Symposium on Foundations of Computer Science (FOCS), pp. 606–635. Cited by: §1.
- [BRE73] (1973) Reducing the retrieval time of scatter storage techniques. Communications of the ACM 16 (2), pp. 105–109. External Links: Document Cited by: §1, §1.
- [CM86] (1986) Techniques for collision resolution in hash tables with open addressing. In Proceedings of the 1986 Fall Joint Computer Conference, pp. 601–610. Cited by: §1, §1.
- [CEL86] (1986) Robin hood hashing. Ph.D. Thesis, University of Waterloo. Cited by: §1.
- [DdP+06] (2006) De dictionariis dynamicis pauco spatio utentibus: (lat. on dynamic dictionaries using little space). In Latin American Symposium on Theoretical Informatics, pp. 349–361. Cited by: §1.
- [DW05] (2005) Balanced allocation and dictionaries with tightly packed constant size bins. In Proceedings of the 32nd International Colloquium on Automata, Languages and Programming (ICALP), pp. 166–178. Cited by: §1.
- [FKK24] (2024) Optimal bounds for open addressing without reordering. In Proceedings of the 65th IEEE Symposium on Foundations of Computer Science (FOCS), pp. 594–605. External Links: Document Cited by: §1, §2.
- [FNS+88] (1988) Non-oblivious hashing. In Proceedings of the twentieth annual ACM symposium on Theory of computing, pp. 367–376. Cited by: §1.
- [FN93] (1993) Implicit o(1) probe search. SIAM Journal on Computing 22 (1), pp. 1–10. Cited by: §1.
- [FPS+03] (2003) Space efficient hash tables with worst case constant access time. In Proceedings of the 20th Annual Symposium on Theoretical Aspects of Computer Science (STACS), pp. 271–282. Cited by: §1.
- [GM79] (1979) Efficient ordering of hash tables. SIAM Journal on Computing 8 (3), pp. 463–478. Cited by: §1.
- [KNU98] (1998) The art of computer programming, volume 3: sorting and searching. 2nd edition, Addison-Wesley. Cited by: §1, §1.
- [LLY+23] (2023) Tight cell-probe lower bounds for dynamic succinct dictionaries. In Proceedings of the 64th IEEE Annual Symposium on Foundations of Computer Science (FOCS), pp. 1842–1862. Cited by: §1.
- [LLY+24] (2024) Dynamic dictionary with subconstant wasted bits per key. In Proceedings of the 35th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pp. 171–207. Cited by: §1.
- [LYO78] (1978) Packed scatter tables. Communications of the ACM 21 (10), pp. 857–865. Cited by: §1.
- [MAL77] (1977) Scatter storage techniques: a unifying viewpoint and a method for reducing retrieval times. The Computer Journal 20 (2), pp. 137–140. Cited by: §1.
- [POB77] (1977) Studies on hash coding with open addressing. M. Math Essay, University of Waterloo. Cited by: §1.
- [RRR03] (2003) Succinct dynamic dictionaries and trees. In Proceedings of the 30th International Colloquium on Automata, Languages and Programming (ICALP), pp. 357–368. Cited by: §1.