🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 152 (from laksa066)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
4 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.2 months ago (distributed domain, exempt)
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://en.wikipedia.org/wiki/Perfect_hash_function
Last Crawled2026-04-14 07:08:33 (4 days ago)
First Indexed2013-08-09 09:50:01 (12 years ago)
HTTP Status Code200
Meta TitlePerfect hash function - Wikipedia
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
From Wikipedia, the free encyclopedia A perfect hash function for the four names shown A minimal perfect hash function for the four names shown In computer science , a perfect hash function h for a set S is a hash function that maps distinct elements in S to a set of m integers, with no collisions . In mathematical terms, it is an injective function . Perfect hash functions may be used to implement a lookup table with constant worst-case access time . A perfect hash function can, as any hash function , be used to implement hash tables , with the advantage that no collision resolution has to be implemented. In addition, if the keys are not in the data and if it is known that queried keys will be valid, then the keys do not need to be stored in the lookup table, saving space. Disadvantages of perfect hash functions are that S needs to be known for the construction of the perfect hash function. Non-dynamic perfect hash functions need to be re-constructed if S changes. For frequently changing S dynamic perfect hash functions may be used at the cost of additional space. [ 1 ] The space requirement to store the perfect hash function is in O ( n ) where n is the number of keys in the structure. The important performance parameters for perfect hash functions are the evaluation time, which should be constant, the construction time, and the representation size. A perfect hash function with values in a limited range can be used for efficient lookup operations, by placing keys from S (or other associated values) in a lookup table indexed by the output of the function. One can then test whether a key is present in S , or look up a value associated with that key, by looking for it at its cell of the table. Each such lookup takes constant time in the worst case . [ 2 ] With perfect hashing, the associated data can be read or written with a single access to the table. [ 3 ] Performance of perfect hash functions [ edit ] The important performance parameters for perfect hashing are the representation size, the evaluation time, the construction time, and additionally the range requirement (average number of buckets per key in the hash table). [ 4 ] The evaluation time can be as fast as O ( 1 ) , which is optimal. [ 2 ] [ 4 ] The construction time needs to be at least O ( n ) , because each element in S needs to be considered, and S contains n elements. This lower bound can be achieved in practice. [ 4 ] The lower bound for the representation size depends on m and n . Let m = (1+ε) n and h a perfect hash function. A good approximation for the lower bound is Bits per element. For minimal perfect hashing, ε = 0 , the lower bound is log e ≈ 1.44 bits per element. [ 4 ] A perfect hash function for a specific set S that can be evaluated in constant time, and with values in a small range, can be found by a randomized algorithm in a number of operations that is proportional to the size of S. The original construction of Fredman, Komlós & Szemerédi (1984) uses a two-level scheme to map a set S of n elements to a range of O ( n ) indices, and then map each index to a range of hash values. The first level of their construction chooses a large prime p (larger than the size of the universe from which S is drawn), and a parameter k , and maps each element x of S to the index If k is chosen randomly, this step is likely to have collisions, but the number of elements n i that are simultaneously mapped to the same index i is likely to be small. The second level of their construction assigns disjoint ranges of O ( n i 2 ) integers to each index i . It uses a second set of linear modular functions, one for each index i , to map each member x of S into the range associated with g ( x ) . [ 2 ] As Fredman, Komlós & Szemerédi (1984) show, there exists a choice of the parameter k such that the sum of the lengths of the ranges for the n different values of g ( x ) is O ( n ) . Additionally, for each value of g ( x ) , there exists a linear modular function that maps the corresponding subset of S into the range associated with that value. Both k , and the second-level functions for each value of g ( x ) , can be found in polynomial time by choosing values randomly until finding one that works. [ 2 ] The hash function itself requires storage space O ( n ) to store k , p , and all of the second-level linear modular functions. Computing the hash value of a given key x may be performed in constant time by computing g ( x ) , looking up the second-level function associated with g ( x ) , and applying this function to x . A modified version of this two-level scheme with a larger number of values at the top level can be used to construct a perfect hash function that maps S into a smaller range of length n + o ( n ) . [ 2 ] A more recent method for constructing a perfect hash function is described by Belazzougui, Botelho & Dietzfelbinger (2009) as "hash, displace, and compress". Here a first-level hash function g is also used to map elements onto a range of r integers. An element x ∈ S is stored in the Bucket B g(x) . [ 4 ] Then, in descending order of size, each bucket's elements are hashed by a hash function of a sequence of independent fully random hash functions (Φ 1 , Φ 2 , Φ 3 , ...) , starting with Φ 1 . If the hash function does not produce any collisions for the bucket, and the resulting values are not yet occupied by other elements from other buckets, the function is chosen for that bucket. If not, the next hash function in the sequence is tested. [ 4 ] To evaluate the perfect hash function h ( x ) one only has to save the mapping σ of the bucket index g ( x ) onto the correct hash function in the sequence, resulting in h(x) = Φ σ(g(x)) . [ 4 ] Finally, to reduce the representation size, the ( σ(i)) 0 ≤ i < r are compressed into a form that still allows the evaluation in O ( 1 ) . [ 4 ] This approach needs linear time in n for construction, and constant evaluation time. The representation size is in O ( n ) , and depends on the achieved range. For example, with m = 1.23 n Belazzougui, Botelho & Dietzfelbinger (2009) achieved a representation size between 3.03 bits/key and 1.40 bits/key for their given example set of 10 million entries, with lower values needing a higher computation time. The space lower bound in this scenario is 0.88 bits/key. [ 4 ] This section is missing information about RecSplit & "fingerprinting" recsplit paper . Please expand the section to include this information. Further details may exist on the talk page . ( March 2023 ) algorithm hash, displace, and compress is (1) Split S into buckets B i  := g −1 ({i})∩S,0 ≤ i < r (2) Sort buckets B i in falling order according to size |B i | (3) Initialize array T[0...m-1] with 0's (4) for all i   ∈[r], in the order from (2), do (5) for l   ←   1,2,... (6) repeat forming K i   ←   { Φ l (x)|x   ∈   B i } (6) until |K i |=|B i | and K i ∩{j|T[j]=1}=   ∅ (7) let σ(i):= the successful l (8) for all j   ∈   K i let T[j]:=   1 (9) Transform (σ i ) 0≤i<r into compressed form, retaining O ( 1 ) access. The use of O ( n ) words of information to store the function of Fredman, Komlós & Szemerédi (1984) is near-optimal: any perfect hash function that can be calculated in constant time requires at least a number of bits that is proportional to the size of S . [ 5 ] For minimal perfect hash functions the information theoretic space lower bound is bits/key. [ 4 ] For perfect hash functions, it is first assumed that the range of h is bounded by n as m = (1+ε) n . With the formula given by Belazzougui, Botelho & Dietzfelbinger (2009) and for a universe whose size | U | = u tends towards infinity, the space lower bounds is bits/key, minus log( n ) bits overall. [ 4 ] Dynamic perfect hashing [ edit ] Using a perfect hash function is best in situations where there is a frequently queried large set, S , which is seldom updated. This is because any modification of the set S may cause the hash function to no longer be perfect for the modified set. Solutions which update the hash function any time the set is modified are known as dynamic perfect hashing , [ 1 ] but these methods are relatively complicated to implement. Minimal perfect hash function [ edit ] A minimal perfect hash function is a perfect hash function that maps n keys to n consecutive integers – usually the numbers from 0 to n − 1 or from 1 to n . A more formal way of expressing this is: Let j and k be elements of some finite set S . Then h is a minimal perfect hash function if and only if h ( j ) = h ( k ) implies j = k ( injectivity ) and there exists an integer a such that the range of h is a .. a + | S | − 1 . It has been proven that a general purpose minimal perfect hash scheme requires at least bits/key. [ 4 ] Assuming that is a set of size containing integers in the range , it is known how to efficiently construct an explicit minimal perfect hash function from to that uses space bits and that supports constant evaluation time. [ 6 ] In practice, there are minimal perfect hashing schemes that use roughly 1.56 bits/key if given enough time. [ 7 ] [ 8 ] A hash function is k -perfect if at most k elements from S are mapped onto the same value in the range. The "hash, displace, and compress" algorithm can be used to construct k -perfect hash functions by allowing up to k collisions. The changes necessary to accomplish this are minimal, and are underlined in the adapted pseudocode below: (4) for all i   ∈[r], in the order from (2), do (5) for l   ←   1,2,... (6) repeat forming K i   ←   { Φ l (x)|x   ∈   B i } (6) until |K i |=|B i | and K i ∩{j| T[j]=k }=   ∅ (7) let σ(i):= the successful l (8) for all j   ∈   K i set T[j]←T[j]+1 A minimal perfect hash function F is order preserving if keys are given in some order a 1 , a 2 , ..., a n and for any keys a j and a k , j < k implies F ( a j ) < F( a k ) . [ 9 ] In this case, the function value is just the position of each key in the sorted ordering of all of the keys. A simple implementation of order-preserving minimal perfect hash functions with constant access time is to use an (ordinary) perfect hash function to store a lookup table of the positions of each key. This solution uses bits, which is optimal in the setting where the comparison function for the keys may be arbitrary. [ 10 ] However, if the keys a 1 , a 2 , ..., a n are integers drawn from a universe , then it is possible to construct an order-preserving hash function using only bits of space. [ 11 ] Moreover, this bound is known to be optimal. [ 12 ] While well-dimensioned hash tables have amortized average O(1) time (amortized average constant time) for lookups, insertions, and deletion, most hash table algorithms suffer from possible worst-case times that take much longer. A worst-case O(1) time (constant time even in the worst case) would be better for many applications (including network router and memory caches ). [ 13 ] : 41  Few hash table algorithms support worst-case O(1) lookup time (constant lookup time even in the worst case). The few that do include: perfect hashing; dynamic perfect hashing ; cuckoo hashing ; hopscotch hashing ; and extendible hashing . [ 13 ] : 42–69  A simple alternative to perfect hashing, which also allows dynamic updates, is cuckoo hashing . This scheme maps keys to two or more locations within a range (unlike perfect hashing which maps each key to a single location) but does so in such a way that the keys can be assigned one-to-one to locations to which they have been mapped. Lookups with this scheme are slower, because multiple locations must be checked, but nevertheless take constant worst-case time. [ 14 ] ^ a b Dietzfelbinger, Martin; Karlin, Anna ; Mehlhorn, Kurt ; Meyer auf der Heide, Friedhelm; Rohnert, Hans; Tarjan, Robert E. (1994), "Dynamic perfect hashing: upper and lower bounds", SIAM Journal on Computing , 23 (4): 738– 761, doi : 10.1137/S0097539791194094 , MR   1283572 . ^ a b c d e Fredman, Michael L. ; Komlós, János ; Szemerédi, Endre (1984), "Storing a Sparse Table with O (1) Worst Case Access Time", Journal of the ACM , 31 (3): 538, doi : 10.1145/828.1884 , MR   0819156 , S2CID   5399743 ^ Lu, Yi ; Prabhakar, Balaji ; Bonomi, Flavio (2006), "Perfect Hashing for Network Applications", 2006 IEEE International Symposium on Information Theory , pp.  2774– 2778, doi : 10.1109/ISIT.2006.261567 , ISBN   1-4244-0505-X , S2CID   1494710 ^ a b c d e f g h i j k l Belazzougui, Djamal; Botelho, Fabiano C.; Dietzfelbinger, Martin (2009), "Hash, displace, and compress" (PDF) , Algorithms - ESA 2009 (PDF) , Lecture Notes in Computer Science , vol. 5757, Berlin: Springer, pp.  682– 693, CiteSeerX   10.1.1.568.130 , doi : 10.1007/978-3-642-04128-0_61 , ISBN   978-3-642-04127-3 , MR   2557794 . ^ Fredman, Michael L. ; Komlós, János (1984), "On the size of separating systems and families of perfect hash functions", SIAM Journal on Algebraic and Discrete Methods , 5 (1): 61– 68, doi : 10.1137/0605009 , MR   0731857 . ^ Hagerup, Torben; Tholey, Torsten (2001), "Efficient Minimal Perfect Hashing in Nearly Minimal Space" , STACS 2001 , Berlin, Heidelberg: Springer Berlin Heidelberg, pp.  317– 326, doi : 10.1007/3-540-44693-1_28 , ISBN   978-3-540-41695-1 , retrieved 2023-11-12 {{ citation }} : CS1 maint: work parameter with ISBN ( link ) ^ Esposito, Emmanuel; Mueller Graf, Thomas; Vigna, Sebastiano (2020), "RecSplit: Minimal Perfect Hashing via Recursive Splitting", 2020 Proceedings of the Symposium on Algorithm Engineering and Experiments (ALENEX) , Proceedings , pp.  175– 185, arXiv : 1910.06416 , doi : 10.1137/1.9781611976007.14 . ^ minimal-perfect-hash (GitHub) ^ Jenkins, Bob (14 April 2009), "order-preserving minimal perfect hashing", in Black, Paul E. (ed.), Dictionary of Algorithms and Data Structures , U.S. National Institute of Standards and Technology , retrieved 2013-03-05 ^ Fox, Edward A.; Chen, Qi Fan; Daoud, Amjad M.; Heath, Lenwood S. (July 1991), "Order-preserving minimal perfect hash functions and information retrieval" (PDF) , ACM Transactions on Information Systems , 9 (3), New York, NY, USA: ACM: 281– 308, doi : 10.1145/125187.125200 , S2CID   53239140 . ^ Belazzougui, Djamal; Boldi, Paolo; Pagh, Rasmus ; Vigna, Sebastiano (November 2008), "Theory and practice of monotone minimal perfect hashing", Journal of Experimental Algorithmics , 16 , Art. no. 3.2, 26pp, doi : 10.1145/1963190.2025378 , S2CID   2367401 . ^ Assadi, Sepehr; Farach-Colton, Martín; Kuszmaul, William (January 2023), "Tight Bounds for Monotone Minimal Perfect Hashing" , Proceedings of the 2023 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA) , Philadelphia, PA: Society for Industrial and Applied Mathematics, pp.  456– 476, arXiv : 2207.10556 , doi : 10.1137/1.9781611977554.ch20 , ISBN   978-1-61197-755-4 , retrieved 2023-04-27 {{ citation }} : CS1 maint: work parameter with ISBN ( link ) ^ a b Timothy A. Davis. "Chapter 5 Hashing" : subsection "Hash Tables with Worst-Case O(1) Access" ^ Pagh, Rasmus ; Rodler, Flemming Friche (2004), "Cuckoo hashing", Journal of Algorithms , 51 (2): 122– 144, doi : 10.1016/j.jalgor.2003.12.002 , MR   2050140 . Richard J. Cichelli. Minimal Perfect Hash Functions Made Simple , Communications of the ACM, Vol. 23, Number 1, January 1980. Thomas H. Cormen , Charles E. Leiserson , Ronald L. Rivest , and Clifford Stein . Introduction to Algorithms , Third Edition. MIT Press, 2009. ISBN   978-0262033848 . Section 11.5: Perfect hashing, pp. 267, 277–282. Fabiano C. Botelho, Rasmus Pagh and Nivio Ziviani. "Perfect Hashing for Data Management Applications" . Fabiano C. Botelho and Nivio Ziviani . "External perfect hashing for very large key sets" . 16th ACM Conference on Information and Knowledge Management (CIKM07), Lisbon, Portugal, November 2007. Djamal Belazzougui, Paolo Boldi, Rasmus Pagh , and Sebastiano Vigna. "Monotone minimal perfect hashing: Searching a sorted table with O(1) accesses" . In Proceedings of the 20th Annual ACM-SIAM Symposium On Discrete Mathematics (SODA), New York, 2009. ACM Press. Marshall D. Brain and Alan L. Tharp. "Near-perfect Hashing of Large Word Sets". Software—Practice and Experience, vol. 19(10), 967-078, October 1989. John Wiley & Sons. Douglas C. Schmidt, GPERF: A Perfect Hash Function Generator , C++ Report, SIGS, Vol. 10, No. 10, November/December, 1998. Hans-Peter Lehmann, Thomas Mueller, Rasmus Pagh, Giulio Ermanno Pibiri, Peter Sanders, Sebastiano Vigna, Stefan Walzer, "Modern Minimal Perfect Hashing: A Survey", arXiv : 2506.06536 , June 2025. Discusses post-1997 developments in the field. gperf is an open source C and C++ perfect hash generator (very fast, but only works for small sets) Minimal Perfect Hashing (bob algorithm) by Bob Jenkins cmph : C Minimal Perfect Hashing Library, open source implementations for many (minimal) perfect hashes (works for big sets) Sux4J : open source monotone minimal perfect hashing in Java MPHSharp : perfect hashing methods in C# BBHash : minimal perfect hash function in header-only C++ Perfect::Hash , perfect hash generator in Perl that makes C code. Has a "prior art" section worth looking at.
Markdown
[Jump to content](https://en.wikipedia.org/wiki/Perfect_hash_function#bodyContent) Main menu Main menu move to sidebar hide Navigation - [Main page](https://en.wikipedia.org/wiki/Main_Page "Visit the main page [z]") - [Contents](https://en.wikipedia.org/wiki/Wikipedia:Contents "Guides to browsing Wikipedia") - [Current events](https://en.wikipedia.org/wiki/Portal:Current_events "Articles related to current events") - [Random article](https://en.wikipedia.org/wiki/Special:Random "Visit a randomly selected article [x]") - [About Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:About "Learn about Wikipedia and how it works") - [Contact us](https://en.wikipedia.org/wiki/Wikipedia:Contact_us "How to contact Wikipedia") Contribute - [Help](https://en.wikipedia.org/wiki/Help:Contents "Guidance on how to use and edit Wikipedia") - [Learn to edit](https://en.wikipedia.org/wiki/Help:Introduction "Learn how to edit Wikipedia") - [Community portal](https://en.wikipedia.org/wiki/Wikipedia:Community_portal "The hub for editors") - [Recent changes](https://en.wikipedia.org/wiki/Special:RecentChanges "A list of recent changes to Wikipedia [r]") - [Upload file](https://en.wikipedia.org/wiki/Wikipedia:File_upload_wizard "Add images or other media for use on Wikipedia") - [Special pages](https://en.wikipedia.org/wiki/Special:SpecialPages "A list of all special pages [q]") [![](https://en.wikipedia.org/static/images/icons/enwiki-25.svg) ![Wikipedia](https://en.wikipedia.org/static/images/mobile/copyright/wikipedia-wordmark-en-25.svg) ![The Free Encyclopedia](https://en.wikipedia.org/static/images/mobile/copyright/wikipedia-tagline-en-25.svg)](https://en.wikipedia.org/wiki/Main_Page) [Search](https://en.wikipedia.org/wiki/Special:Search "Search Wikipedia [f]") Appearance - [Donate](https://donate.wikimedia.org/?wmf_source=donate&wmf_medium=sidebar&wmf_campaign=en.wikipedia.org&uselang=en) - [Create account](https://en.wikipedia.org/w/index.php?title=Special:CreateAccount&returnto=Perfect+hash+function "You are encouraged to create an account and log in; however, it is not mandatory") - [Log in](https://en.wikipedia.org/w/index.php?title=Special:UserLogin&returnto=Perfect+hash+function "You're encouraged to log in; however, it's not mandatory. [o]") Personal tools - [Donate](https://donate.wikimedia.org/?wmf_source=donate&wmf_medium=sidebar&wmf_campaign=en.wikipedia.org&uselang=en) - [Create account](https://en.wikipedia.org/w/index.php?title=Special:CreateAccount&returnto=Perfect+hash+function "You are encouraged to create an account and log in; however, it is not mandatory") - [Log in](https://en.wikipedia.org/w/index.php?title=Special:UserLogin&returnto=Perfect+hash+function "You're encouraged to log in; however, it's not mandatory. [o]") ## Contents move to sidebar hide - [(Top)](https://en.wikipedia.org/wiki/Perfect_hash_function) - [1 Application](https://en.wikipedia.org/wiki/Perfect_hash_function#Application) - [2 Performance of perfect hash functions](https://en.wikipedia.org/wiki/Perfect_hash_function#Performance_of_perfect_hash_functions) - [3 Construction](https://en.wikipedia.org/wiki/Perfect_hash_function#Construction) Toggle Construction subsection - [3\.1 Pseudocode](https://en.wikipedia.org/wiki/Perfect_hash_function#Pseudocode) - [4 Space lower bounds](https://en.wikipedia.org/wiki/Perfect_hash_function#Space_lower_bounds) - [5 Extensions](https://en.wikipedia.org/wiki/Perfect_hash_function#Extensions) Toggle Extensions subsection - [5\.1 Dynamic perfect hashing](https://en.wikipedia.org/wiki/Perfect_hash_function#Dynamic_perfect_hashing) - [5\.2 Minimal perfect hash function](https://en.wikipedia.org/wiki/Perfect_hash_function#Minimal_perfect_hash_function) - [5\.3 k-perfect hashing](https://en.wikipedia.org/wiki/Perfect_hash_function#k-perfect_hashing) - [5\.4 Order preservation](https://en.wikipedia.org/wiki/Perfect_hash_function#Order_preservation) - [6 Related constructions](https://en.wikipedia.org/wiki/Perfect_hash_function#Related_constructions) - [7 References](https://en.wikipedia.org/wiki/Perfect_hash_function#References) - [8 Further reading](https://en.wikipedia.org/wiki/Perfect_hash_function#Further_reading) - [9 External links](https://en.wikipedia.org/wiki/Perfect_hash_function#External_links) Toggle the table of contents # Perfect hash function 6 languages - [Čeština](https://cs.wikipedia.org/wiki/Dokonal%C3%A9_ha%C5%A1ov%C3%A1n%C3%AD "Dokonalé hašování – Czech") - [Deutsch](https://de.wikipedia.org/wiki/Perfekte_Hash-Funktion "Perfekte Hash-Funktion – German") - [فارسی](https://fa.wikipedia.org/wiki/%D8%AA%D8%A7%D8%A8%D8%B9_%D8%AF%D8%B1%D9%87%D9%85%E2%80%8C%D8%B3%D8%A7%D8%B2%DB%8C_%DA%A9%D8%A7%D9%85%D9%84 "تابع درهم‌سازی کامل – Persian") - [Français](https://fr.wikipedia.org/wiki/Fonction_de_hachage_parfait "Fonction de hachage parfait – French") - [Српски / srpski](https://sr.wikipedia.org/wiki/%D0%A1%D0%B0%D0%B2%D1%80%D1%88%D0%B5%D0%BD%D0%B0_%D1%85%D0%B5%D1%88_%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%98%D0%B0 "Савршена хеш функција – Serbian") - [中文](https://zh.wikipedia.org/wiki/%E5%AE%8C%E7%BE%8E%E6%95%A3%E5%88%97 "完美散列 – Chinese") [Edit links](https://www.wikidata.org/wiki/Special:EntityPage/Q2070573#sitelinks-wikipedia "Edit interlanguage links") - [Article](https://en.wikipedia.org/wiki/Perfect_hash_function "View the content page [c]") - [Talk](https://en.wikipedia.org/wiki/Talk:Perfect_hash_function "Discuss improvements to the content page [t]") English - [Read](https://en.wikipedia.org/wiki/Perfect_hash_function) - [Edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit "Edit this page [e]") - [View history](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=history "Past revisions of this page [h]") Tools Tools move to sidebar hide Actions - [Read](https://en.wikipedia.org/wiki/Perfect_hash_function) - [Edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit "Edit this page [e]") - [View history](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=history) General - [What links here](https://en.wikipedia.org/wiki/Special:WhatLinksHere/Perfect_hash_function "List of all English Wikipedia pages containing links to this page [j]") - [Related changes](https://en.wikipedia.org/wiki/Special:RecentChangesLinked/Perfect_hash_function "Recent changes in pages linked from this page [k]") - [Upload file](https://en.wikipedia.org/wiki/Wikipedia:File_Upload_Wizard "Upload files [u]") - [Permanent link](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&oldid=1318938338 "Permanent link to this revision of this page") - [Page information](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=info "More information about this page") - [Cite this page](https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page=Perfect_hash_function&id=1318938338&wpFormIdentifier=titleform "Information on how to cite this page") - [Get shortened URL](https://en.wikipedia.org/w/index.php?title=Special:UrlShortener&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPerfect_hash_function) Print/export - [Download as PDF](https://en.wikipedia.org/w/index.php?title=Special:DownloadAsPdf&page=Perfect_hash_function&action=show-download-screen "Download this page as a PDF file") - [Printable version](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&printable=yes "Printable version of this page [p]") In other projects - [Wikidata item](https://www.wikidata.org/wiki/Special:EntityPage/Q2070573 "Structured data on this page hosted by Wikidata [g]") Appearance move to sidebar hide From Wikipedia, the free encyclopedia Hash function without any collisions [![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Hash_table_4_1_1_0_0_0_0_LL.svg/250px-Hash_table_4_1_1_0_0_0_0_LL.svg.png)](https://en.wikipedia.org/wiki/File:Hash_table_4_1_1_0_0_0_0_LL.svg) A perfect hash function for the four names shown [![](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Hash_table_4_1_0_0_0_0_0_LL.svg/250px-Hash_table_4_1_0_0_0_0_0_LL.svg.png)](https://en.wikipedia.org/wiki/File:Hash_table_4_1_0_0_0_0_0_LL.svg) A minimal perfect hash function for the four names shown In [computer science](https://en.wikipedia.org/wiki/Computer_science "Computer science"), a **perfect hash function** h for a set S is a [hash function](https://en.wikipedia.org/wiki/Hash_function "Hash function") that maps distinct elements in S to a set of m integers, with no [collisions](https://en.wikipedia.org/wiki/Hash_collision "Hash collision"). In mathematical terms, it is an [injective function](https://en.wikipedia.org/wiki/Injective_function "Injective function"). Perfect hash functions may be used to implement a [lookup table](https://en.wikipedia.org/wiki/Lookup_table "Lookup table") with constant worst-case [access time](https://en.wikipedia.org/wiki/Access_time "Access time"). A perfect hash function can, as any [hash function](https://en.wikipedia.org/wiki/Hash_function "Hash function"), be used to implement [hash tables](https://en.wikipedia.org/wiki/Hash_table "Hash table"), with the advantage that no [collision resolution](https://en.wikipedia.org/wiki/Hash_table#Collision_resolution "Hash table") has to be implemented. In addition, if the keys are not in the data and if it is known that queried keys will be valid, then the keys do not need to be stored in the lookup table, saving space. Disadvantages of perfect hash functions are that S needs to be known for the construction of the perfect hash function. Non-dynamic perfect hash functions need to be re-constructed if S changes. For frequently changing S [dynamic perfect hash functions](https://en.wikipedia.org/wiki/Dynamic_perfect_hashing "Dynamic perfect hashing") may be used at the cost of additional space.[\[1\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-DynamicPerfectHashing-1) The space requirement to store the perfect hash function is in *O*(*n*) where *n* is the number of keys in the structure. The important performance parameters for perfect hash functions are the evaluation time, which should be constant, the construction time, and the representation size. ## Application \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=1 "Edit section: Application")\] A perfect hash function with values in a limited range can be used for efficient lookup operations, by placing keys from S (or other associated values) in a [lookup table](https://en.wikipedia.org/wiki/Lookup_table "Lookup table") indexed by the output of the function. One can then test whether a key is present in S, or look up a value associated with that key, by looking for it at its cell of the table. Each such lookup takes [constant time](https://en.wikipedia.org/wiki/Constant_time "Constant time") in the [worst case](https://en.wikipedia.org/wiki/Worst-case_complexity "Worst-case complexity").[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) With perfect hashing, the associated data can be read or written with a single access to the table.[\[3\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-3) ## Performance of perfect hash functions \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=2 "Edit section: Performance of perfect hash functions")\] The important performance parameters for perfect hashing are the representation size, the evaluation time, the construction time, and additionally the range requirement m n {\\displaystyle {\\frac {m}{n}}} ![{\\displaystyle {\\frac {m}{n}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/d48d87468620ad6c70385ddd0d024577ccb559e1) (average number of buckets per key in the hash table).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) The evaluation time can be as fast as *O*(*1*), which is optimal.[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2)[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) The construction time needs to be at least *O*(*n*), because each element in S needs to be considered, and S contains n elements. This lower bound can be achieved in practice.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) The lower bound for the representation size depends on m and n. Let *m* = (1+ε) *n* and h a perfect hash function. A good approximation for the lower bound is log ⁡ e − ε log ⁡ 1 \+ ε ε {\\displaystyle \\log e-\\varepsilon \\log {\\frac {1+\\varepsilon }{\\varepsilon }}} ![{\\displaystyle \\log e-\\varepsilon \\log {\\frac {1+\\varepsilon }{\\varepsilon }}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/b02a088abd50352f229055b2573a6cb24e70ea05) Bits per element. For minimal perfect hashing, ε = 0, the lower bound is log e ≈ 1.44 bits per element.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) ## Construction \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=3 "Edit section: Construction")\] A perfect hash function for a specific set S that can be evaluated in constant time, and with values in a small range, can be found by a [randomized algorithm](https://en.wikipedia.org/wiki/Randomized_algorithm "Randomized algorithm") in a number of operations that is proportional to the size of S. The original construction of [Fredman, Komlós & Szemerédi (1984)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFFredmanKoml%C3%B3sSzemer%C3%A9di1984) uses a two-level scheme to map a set S of n elements to a range of *O*(*n*) indices, and then map each index to a range of hash values. The first level of their construction chooses a large prime p (larger than the size of the [universe](https://en.wikipedia.org/wiki/Universe_\(mathematics\) "Universe (mathematics)") from which S is drawn), and a parameter k, and maps each element x of S to the index g ( x ) \= ( k x mod p ) mod n . {\\displaystyle g(x)=(kx{\\bmod {p}}){\\bmod {n}}.} ![{\\displaystyle g(x)=(kx{\\bmod {p}}){\\bmod {n}}.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/0eed5c339f42fdccc1685d8d3b1af928e2a3be01) If k is chosen randomly, this step is likely to have collisions, but the number of elements ni that are simultaneously mapped to the same index i is likely to be small. The second level of their construction assigns disjoint ranges of *O*(*ni*2) integers to each index i. It uses a second set of linear modular functions, one for each index i, to map each member x of S into the range associated with *g*(*x*).[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) As [Fredman, Komlós & Szemerédi (1984)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFFredmanKoml%C3%B3sSzemer%C3%A9di1984) show, there exists a choice of the parameter k such that the sum of the lengths of the ranges for the n different values of *g*(*x*) is *O*(*n*). Additionally, for each value of *g*(*x*), there exists a linear modular function that maps the corresponding subset of S into the range associated with that value. Both k, and the second-level functions for each value of *g*(*x*), can be found in [polynomial time](https://en.wikipedia.org/wiki/Polynomial_time "Polynomial time") by choosing values randomly until finding one that works.[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) The hash function itself requires storage space *O*(*n*) to store k, p, and all of the second-level linear modular functions. Computing the hash value of a given key x may be performed in constant time by computing *g*(*x*), looking up the second-level function associated with *g*(*x*), and applying this function to x. A modified version of this two-level scheme with a larger number of values at the top level can be used to construct a perfect hash function that maps S into a smaller range of length *n* + *o*(*n*).[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) A more recent method for constructing a perfect hash function is described by [Belazzougui, Botelho & Dietzfelbinger (2009)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFBelazzouguiBotelhoDietzfelbinger2009) as "hash, displace, and compress". Here a first-level hash function g is also used to map elements onto a range of r integers. An element *x* ∈ *S* is stored in the Bucket Bg(x).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) Then, in descending order of size, each bucket's elements are hashed by a hash function of a sequence of independent fully random hash functions (Φ1, Φ2, Φ3, ...), starting with Φ1. If the hash function does not produce any collisions for the bucket, and the resulting values are not yet occupied by other elements from other buckets, the function is chosen for that bucket. If not, the next hash function in the sequence is tested.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) To evaluate the perfect hash function *h*(*x*) one only has to save the mapping σ of the bucket index *g*(*x*) onto the correct hash function in the sequence, resulting in h(x) = Φσ(g(x)).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) Finally, to reduce the representation size, the (σ(i))0 ≤ i \< r are compressed into a form that still allows the evaluation in *O*(*1*).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) This approach needs linear time in n for construction, and constant evaluation time. The representation size is in *O*(*n*), and depends on the achieved range. For example, with *m* = 1.23*n* [Belazzougui, Botelho & Dietzfelbinger (2009)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFBelazzouguiBotelhoDietzfelbinger2009) achieved a representation size between 3.03 bits/key and 1.40 bits/key for their given example set of 10 million entries, with lower values needing a higher computation time. The space lower bound in this scenario is 0.88 bits/key.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) | | | |---|---| | [![icon](https://upload.wikimedia.org/wikipedia/en/thumb/6/6c/Wiki_letter_w.svg/60px-Wiki_letter_w.svg.png)](https://en.wikipedia.org/wiki/File:Wiki_letter_w.svg) | This section **is missing information** about RecSplit & "fingerprinting" [recsplit paper](https://epubs.siam.org/doi/pdf/10.1137/1.9781611976007.14). Please expand the section to include this information. Further details may exist on the [talk page](https://en.wikipedia.org/wiki/Talk:Perfect_hash_function "Talk:Perfect hash function"). *(March 2023)* | ### Pseudocode \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=4 "Edit section: Pseudocode")\] ``` algorithm hash, displace, and compress is (1) Split S into buckets Bi := g−1({i})∩S,0 ≤ i < r (2) Sort buckets Bi in falling order according to size |Bi| (3) Initialize array T[0...m-1] with 0's (4) for all i ∈[r], in the order from (2), do (5) for l ← 1,2,... (6) repeat forming Ki ← {Φl(x)|x ∈ Bi} (6) until |Ki|=|Bi| and Ki∩{j|T[j]=1}= ∅ (7) let σ(i):= the successful l (8) for all j ∈ Ki let T[j]:= 1 (9) Transform (σi)0≤i<r into compressed form, retaining O(1) access. ``` ## Space lower bounds \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=5 "Edit section: Space lower bounds")\] The use of *O*(*n*) words of information to store the function of [Fredman, Komlós & Szemerédi (1984)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFFredmanKoml%C3%B3sSzemer%C3%A9di1984) is near-optimal: any perfect hash function that can be calculated in constant time requires at least a number of bits that is proportional to the size of S.[\[5\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-5) For minimal perfect hash functions the information theoretic space lower bound is log 2 ⁡ e ≈ 1\.44 {\\displaystyle \\log \_{2}e\\approx 1.44} ![{\\displaystyle \\log \_{2}e\\approx 1.44}](https://wikimedia.org/api/rest_v1/media/math/render/svg/0fd72ec3b460d6cf5434f1a0bb5bb5d24b4b2d15) bits/key.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) For perfect hash functions, it is first assumed that the range of h is bounded by n as *m* = (1+ε) *n*. With the formula given by [Belazzougui, Botelho & Dietzfelbinger (2009)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFBelazzouguiBotelhoDietzfelbinger2009) and for a [universe](https://en.wikipedia.org/wiki/Universe_\(mathematics\) "Universe (mathematics)") U ⊇ S {\\displaystyle U\\supseteq S} ![{\\displaystyle U\\supseteq S}](https://wikimedia.org/api/rest_v1/media/math/render/svg/16992fcab6da9089922e110403a580e2df030419) whose size \|*U*\| = *u* tends towards infinity, the space lower bounds is log 2 ⁡ e − ε log ⁡ 1 \+ ε ε {\\displaystyle \\log \_{2}e-\\varepsilon \\log {\\frac {1+\\varepsilon }{\\varepsilon }}} ![{\\displaystyle \\log \_{2}e-\\varepsilon \\log {\\frac {1+\\varepsilon }{\\varepsilon }}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/776f6c7e58c34f514e1be99b98abdf9f15e14e2a) bits/key, minus log(*n*) bits overall.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) ## Extensions \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=6 "Edit section: Extensions")\] ### Dynamic perfect hashing \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=7 "Edit section: Dynamic perfect hashing")\] Main article: [Dynamic perfect hashing](https://en.wikipedia.org/wiki/Dynamic_perfect_hashing "Dynamic perfect hashing") Using a perfect hash function is best in situations where there is a frequently queried large set, S, which is seldom updated. This is because any modification of the set S may cause the hash function to no longer be perfect for the modified set. Solutions which update the hash function any time the set is modified are known as [dynamic perfect hashing](https://en.wikipedia.org/wiki/Dynamic_perfect_hashing "Dynamic perfect hashing"),[\[1\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-DynamicPerfectHashing-1) but these methods are relatively complicated to implement. ### Minimal perfect hash function \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=8 "Edit section: Minimal perfect hash function")\] A minimal perfect hash function is a perfect hash function that maps n keys to n consecutive integers – usually the numbers from 0 to *n* − 1 or from 1 to n. A more formal way of expressing this is: Let j and k be elements of some finite set S. Then h is a minimal perfect hash function if and only if *h*(*j*) = *h*(*k*) implies *j* = *k* ([injectivity](https://en.wikipedia.org/wiki/Injectivity "Injectivity")) and there exists an integer a such that the range of h is *a*..*a* + \|*S*\| − 1. It has been proven that a general purpose minimal perfect hash scheme requires at least log 2 ⁡ e ≈ 1\.44 {\\displaystyle \\log \_{2}e\\approx 1.44} ![{\\displaystyle \\log \_{2}e\\approx 1.44}](https://wikimedia.org/api/rest_v1/media/math/render/svg/0fd72ec3b460d6cf5434f1a0bb5bb5d24b4b2d15) bits/key.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) Assuming that S {\\displaystyle S} ![{\\displaystyle S}](https://wikimedia.org/api/rest_v1/media/math/render/svg/4611d85173cd3b508e67077d4a1252c9c05abca2) is a set of size n {\\displaystyle n} ![{\\displaystyle n}](https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b) containing integers in the range \[ 1 , 2 o ( n ) \] {\\displaystyle \[1,2^{o(n)}\]} ![{\\displaystyle \[1,2^{o(n)}\]}](https://wikimedia.org/api/rest_v1/media/math/render/svg/f0ac67d15f0cd602c935e60c92e1d2cf4bb68bff), it is known how to efficiently construct an explicit minimal perfect hash function from S {\\displaystyle S} ![{\\displaystyle S}](https://wikimedia.org/api/rest_v1/media/math/render/svg/4611d85173cd3b508e67077d4a1252c9c05abca2) to { 1 , 2 , … , n } {\\displaystyle \\{1,2,\\ldots ,n\\}} ![{\\displaystyle \\{1,2,\\ldots ,n\\}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/4ebfec86b3f22a18f086275390917d5aaa2d8c22) that uses space n log 2 ⁡ e \+ o ( n ) {\\displaystyle n\\log \_{2}e+o(n)} ![{\\displaystyle n\\log \_{2}e+o(n)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/09277f1ba7d62f18c983de0af01dd3deea037948)bits and that supports constant evaluation time.[\[6\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-6) In practice, there are minimal perfect hashing schemes that use roughly 1.56 bits/key if given enough time.[\[7\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-RecSplit-7)[\[8\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-8) ### k-perfect hashing \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=9 "Edit section: k-perfect hashing")\] A hash function is k\-perfect if at most k elements from S are mapped onto the same value in the range. The "hash, displace, and compress" algorithm can be used to construct k\-perfect hash functions by allowing up to k collisions. The changes necessary to accomplish this are minimal, and are underlined in the adapted [pseudocode](https://en.wikipedia.org/wiki/Pseudocode "Pseudocode") below: ``` (4) for all i ∈[r], in the order from (2), do (5) for l ← 1,2,... (6) repeat forming Ki ← {Φl(x)|x ∈ Bi} (6) until |Ki|=|Bi| and Ki∩{j|T[j]=k}= ∅ (7) let σ(i):= the successful l (8) for all j ∈ Ki set T[j]←T[j]+1 ``` ### Order preservation \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=10 "Edit section: Order preservation")\] A minimal perfect hash function F is *order preserving* if keys are given in some order *a*1, *a*2, ..., *a**n* and for any keys *a**j* and *a**k*, *j* \< *k* implies *F*(*a**j*) \< F(*a**k*).[\[9\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-9) In this case, the function value is just the position of each key in the sorted ordering of all of the keys. A simple implementation of order-preserving minimal perfect hash functions with constant access time is to use an (ordinary) perfect hash function to store a lookup table of the positions of each key. This solution uses O ( n log ⁡ n ) {\\displaystyle O(n\\log n)} ![{\\displaystyle O(n\\log n)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/9d2320768fb54880ca4356e61f60eb02a3f9d9f1) bits, which is optimal in the setting where the comparison function for the keys may be arbitrary.[\[10\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-10) However, if the keys *a*1, *a*2, ..., *a**n* are integers drawn from a universe { 1 , 2 , … , U } {\\displaystyle \\{1,2,\\ldots ,U\\}} ![{\\displaystyle \\{1,2,\\ldots ,U\\}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/d2431655ee77a4033df95488cded81c131e07957), then it is possible to construct an order-preserving hash function using only O ( n log ⁡ log ⁡ log ⁡ U ) {\\displaystyle O(n\\log \\log \\log U)} ![{\\displaystyle O(n\\log \\log \\log U)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/760a3917c91c59e973214c6f49cc11d493cfbd92) bits of space.[\[11\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-11) Moreover, this bound is known to be optimal.[\[12\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-12) ## Related constructions \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=11 "Edit section: Related constructions")\] While well-dimensioned hash tables have amortized average O(1) time (amortized average constant time) for lookups, insertions, and deletion, most hash table algorithms suffer from possible worst-case times that take much longer. A worst-case O(1) time (constant time even in the worst case) would be better for many applications (including [network router](https://en.wikipedia.org/wiki/Network_router "Network router") and [memory caches](https://en.wikipedia.org/wiki/Memory_cache "Memory cache")).[\[13\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-davis-13): 41 Few hash table algorithms support worst-case O(1) lookup time (constant lookup time even in the worst case). The few that do include: perfect hashing; [dynamic perfect hashing](https://en.wikipedia.org/wiki/Dynamic_perfect_hashing "Dynamic perfect hashing"); [cuckoo hashing](https://en.wikipedia.org/wiki/Cuckoo_hashing "Cuckoo hashing"); [hopscotch hashing](https://en.wikipedia.org/wiki/Hopscotch_hashing "Hopscotch hashing"); and [extendible hashing](https://en.wikipedia.org/wiki/Extendible_hashing "Extendible hashing").[\[13\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-davis-13): 42–69 A simple alternative to perfect hashing, which also allows dynamic updates, is [cuckoo hashing](https://en.wikipedia.org/wiki/Cuckoo_hashing "Cuckoo hashing"). This scheme maps keys to two or more locations within a range (unlike perfect hashing which maps each key to a single location) but does so in such a way that the keys can be assigned one-to-one to locations to which they have been mapped. Lookups with this scheme are slower, because multiple locations must be checked, but nevertheless take constant worst-case time.[\[14\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-14) ## References \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=12 "Edit section: References")\] 1. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-DynamicPerfectHashing_1-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-DynamicPerfectHashing_1-1) Dietzfelbinger, Martin; [Karlin, Anna](https://en.wikipedia.org/wiki/Anna_Karlin "Anna Karlin"); [Mehlhorn, Kurt](https://en.wikipedia.org/wiki/Kurt_Mehlhorn "Kurt Mehlhorn"); Meyer auf der Heide, Friedhelm; Rohnert, Hans; [Tarjan, Robert E.](https://en.wikipedia.org/wiki/Robert_Tarjan "Robert Tarjan") (1994), "Dynamic perfect hashing: upper and lower bounds", *[SIAM Journal on Computing](https://en.wikipedia.org/wiki/SIAM_Journal_on_Computing "SIAM Journal on Computing")*, **23** (4): 738–761, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/S0097539791194094](https://doi.org/10.1137%2FS0097539791194094), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [1283572](https://mathscinet.ams.org/mathscinet-getitem?mr=1283572) . 2. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-1) [***c***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-2) [***d***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-3) [***e***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-4) [Fredman, Michael L.](https://en.wikipedia.org/wiki/Michael_Fredman "Michael Fredman"); [Komlós, János](https://en.wikipedia.org/wiki/J%C3%A1nos_Koml%C3%B3s_\(mathematician\) "János Komlós (mathematician)"); [Szemerédi, Endre](https://en.wikipedia.org/wiki/Endre_Szemer%C3%A9di "Endre Szemerédi") (1984), "Storing a Sparse Table with *O*(1) Worst Case Access Time", *[Journal of the ACM](https://en.wikipedia.org/wiki/Journal_of_the_ACM "Journal of the ACM")*, **31** (3): 538, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1145/828.1884](https://doi.org/10.1145%2F828.1884), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [0819156](https://mathscinet.ams.org/mathscinet-getitem?mr=0819156), [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [5399743](https://api.semanticscholar.org/CorpusID:5399743) 3. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-3)** [Lu, Yi](https://en.wikipedia.org/w/index.php?title=Yi_Lu_\(computer_scientist\)&action=edit&redlink=1 "Yi Lu (computer scientist) (page does not exist)"); [Prabhakar, Balaji](https://en.wikipedia.org/w/index.php?title=Balaji_Prabhakar&action=edit&redlink=1 "Balaji Prabhakar (page does not exist)"); [Bonomi, Flavio](https://en.wikipedia.org/w/index.php?title=Flavio_Bonomi&action=edit&redlink=1 "Flavio Bonomi (page does not exist)") (2006), "Perfect Hashing for Network Applications", *2006 IEEE International Symposium on Information Theory*, pp. 2774–2778, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1109/ISIT.2006.261567](https://doi.org/10.1109%2FISIT.2006.261567), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [1-4244-0505-X](https://en.wikipedia.org/wiki/Special:BookSources/1-4244-0505-X "Special:BookSources/1-4244-0505-X") , [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [1494710](https://api.semanticscholar.org/CorpusID:1494710) 4. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-1) [***c***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-2) [***d***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-3) [***e***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-4) [***f***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-5) [***g***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-6) [***h***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-7) [***i***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-8) [***j***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-9) [***k***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-10) [***l***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-11) Belazzougui, Djamal; Botelho, Fabiano C.; Dietzfelbinger, Martin (2009), ["Hash, displace, and compress"](https://cmph.sourceforge.net/papers/esa09.pdf) (PDF), [*Algorithms - ESA 2009*](https://cmph.sourceforge.net/papers/esa09.pdf) (PDF), [Lecture Notes in Computer Science](https://en.wikipedia.org/wiki/Lecture_Notes_in_Computer_Science "Lecture Notes in Computer Science"), vol. 5757, Berlin: Springer, pp. 682–693, [CiteSeerX](https://en.wikipedia.org/wiki/CiteSeerX_\(identifier\) "CiteSeerX (identifier)") [10\.1.1.568.130](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.568.130), [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1007/978-3-642-04128-0\_61](https://doi.org/10.1007%2F978-3-642-04128-0_61), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-3-642-04127-3](https://en.wikipedia.org/wiki/Special:BookSources/978-3-642-04127-3 "Special:BookSources/978-3-642-04127-3") , [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [2557794](https://mathscinet.ams.org/mathscinet-getitem?mr=2557794) . 5. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-5)** [Fredman, Michael L.](https://en.wikipedia.org/wiki/Michael_Fredman "Michael Fredman"); [Komlós, János](https://en.wikipedia.org/wiki/J%C3%A1nos_Koml%C3%B3s_\(mathematician\) "János Komlós (mathematician)") (1984), "On the size of separating systems and families of perfect hash functions", *[SIAM Journal on Algebraic and Discrete Methods](https://en.wikipedia.org/wiki/SIAM_Journal_on_Algebraic_and_Discrete_Methods "SIAM Journal on Algebraic and Discrete Methods")*, **5** (1): 61–68, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/0605009](https://doi.org/10.1137%2F0605009), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [0731857](https://mathscinet.ams.org/mathscinet-getitem?mr=0731857) . 6. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-6)** Hagerup, Torben; Tholey, Torsten (2001), ["Efficient Minimal Perfect Hashing in Nearly Minimal Space"](https://dx.doi.org/10.1007/3-540-44693-1_28), *STACS 2001*, Berlin, Heidelberg: Springer Berlin Heidelberg, pp. 317–326, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1007/3-540-44693-1\_28](https://doi.org/10.1007%2F3-540-44693-1_28), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-3-540-41695-1](https://en.wikipedia.org/wiki/Special:BookSources/978-3-540-41695-1 "Special:BookSources/978-3-540-41695-1") , retrieved 2023-11-12 `{{citation}}`: CS1 maint: work parameter with ISBN ([link](https://en.wikipedia.org/wiki/Category:CS1_maint:_work_parameter_with_ISBN "Category:CS1 maint: work parameter with ISBN")) 7. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-RecSplit_7-0)** Esposito, Emmanuel; Mueller Graf, Thomas; Vigna, Sebastiano (2020), "RecSplit: Minimal Perfect Hashing via Recursive Splitting", *2020 Proceedings of the Symposium on Algorithm Engineering and Experiments (ALENEX)*, [Proceedings](https://en.wikipedia.org/wiki/Proceedings "Proceedings"), pp. 175–185, [arXiv](https://en.wikipedia.org/wiki/ArXiv_\(identifier\) "ArXiv (identifier)"):[1910\.06416](https://arxiv.org/abs/1910.06416), [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/1.9781611976007.14](https://doi.org/10.1137%2F1.9781611976007.14) . 8. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-8)** [minimal-perfect-hash (GitHub)](https://github.com/iwiwi/minimal-perfect-hash) 9. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-9)** Jenkins, Bob (14 April 2009), "order-preserving minimal perfect hashing", in Black, Paul E. (ed.), [*Dictionary of Algorithms and Data Structures*](https://xlinux.nist.gov/dads/HTML/orderPreservMinPerfectHash.html), U.S. National Institute of Standards and Technology, retrieved 2013-03-05 10. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-10)** Fox, Edward A.; Chen, Qi Fan; Daoud, Amjad M.; Heath, Lenwood S. (July 1991), ["Order-preserving minimal perfect hash functions and information retrieval"](http://eprints.cs.vt.edu/archive/00000248/01/TR-91-01.pdf) (PDF), *ACM Transactions on Information Systems*, **9** (3), New York, NY, USA: ACM: 281–308, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1145/125187.125200](https://doi.org/10.1145%2F125187.125200), [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [53239140](https://api.semanticscholar.org/CorpusID:53239140) . 11. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-11)** Belazzougui, Djamal; Boldi, Paolo; [Pagh, Rasmus](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh"); Vigna, Sebastiano (November 2008), "Theory and practice of monotone minimal perfect hashing", *Journal of Experimental Algorithmics*, **16**, Art. no. 3.2, 26pp, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1145/1963190.2025378](https://doi.org/10.1145%2F1963190.2025378), [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [2367401](https://api.semanticscholar.org/CorpusID:2367401) . 12. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-12)** Assadi, Sepehr; Farach-Colton, Martín; Kuszmaul, William (January 2023), ["Tight Bounds for Monotone Minimal Perfect Hashing"](https://dx.doi.org/10.1137/1.9781611977554.ch20), *Proceedings of the 2023 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA)*, Philadelphia, PA: Society for Industrial and Applied Mathematics, pp. 456–476, [arXiv](https://en.wikipedia.org/wiki/ArXiv_\(identifier\) "ArXiv (identifier)"):[2207\.10556](https://arxiv.org/abs/2207.10556), [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/1.9781611977554.ch20](https://doi.org/10.1137%2F1.9781611977554.ch20), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-1-61197-755-4](https://en.wikipedia.org/wiki/Special:BookSources/978-1-61197-755-4 "Special:BookSources/978-1-61197-755-4") , retrieved 2023-04-27 `{{citation}}`: CS1 maint: work parameter with ISBN ([link](https://en.wikipedia.org/wiki/Category:CS1_maint:_work_parameter_with_ISBN "Category:CS1 maint: work parameter with ISBN")) 13. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-davis_13-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-davis_13-1) Timothy A. Davis. ["Chapter 5 Hashing"](https://www.cs.wm.edu/~tadavis/cs303/ch05sm.pdf): subsection "Hash Tables with Worst-Case O(1) Access" 14. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-14)** [Pagh, Rasmus](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh"); Rodler, Flemming Friche (2004), "Cuckoo hashing", *Journal of Algorithms*, **51** (2): 122–144, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1016/j.jalgor.2003.12.002](https://doi.org/10.1016%2Fj.jalgor.2003.12.002), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [2050140](https://mathscinet.ams.org/mathscinet-getitem?mr=2050140) . ## Further reading \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=13 "Edit section: Further reading")\] - Richard J. Cichelli. *Minimal Perfect Hash Functions Made Simple*, Communications of the ACM, Vol. 23, Number 1, January 1980. - [Thomas H. Cormen](https://en.wikipedia.org/wiki/Thomas_H._Cormen "Thomas H. Cormen"), [Charles E. Leiserson](https://en.wikipedia.org/wiki/Charles_E._Leiserson "Charles E. Leiserson"), [Ronald L. Rivest](https://en.wikipedia.org/wiki/Ronald_L._Rivest "Ronald L. Rivest"), and [Clifford Stein](https://en.wikipedia.org/wiki/Clifford_Stein "Clifford Stein"). *[Introduction to Algorithms](https://en.wikipedia.org/wiki/Introduction_to_Algorithms "Introduction to Algorithms")*, Third Edition. MIT Press, 2009. [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-0262033848](https://en.wikipedia.org/wiki/Special:BookSources/978-0262033848 "Special:BookSources/978-0262033848") . Section 11.5: Perfect hashing, pp. 267, 277–282. - Fabiano C. Botelho, [Rasmus Pagh](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh") and Nivio Ziviani. ["Perfect Hashing for Data Management Applications"](https://arxiv.org/abs/cs/0702159). - Fabiano C. Botelho and [Nivio Ziviani](https://en.wikipedia.org/wiki/Nivio_Ziviani "Nivio Ziviani"). ["External perfect hashing for very large key sets"](http://homepages.dcc.ufmg.br/~nivio/papers/cikm07.pdf). 16th ACM Conference on Information and Knowledge Management (CIKM07), Lisbon, Portugal, November 2007. - Djamal Belazzougui, Paolo Boldi, [Rasmus Pagh](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh"), and Sebastiano Vigna. ["Monotone minimal perfect hashing: Searching a sorted table with O(1) accesses"](https://web.archive.org/web/20140125080021/http://vigna.dsi.unimi.it/ftp/papers/MonotoneMinimalPerfectHashing.pdf). In Proceedings of the 20th Annual ACM-SIAM Symposium On Discrete Mathematics (SODA), New York, 2009. ACM Press. - Marshall D. Brain and Alan L. Tharp. "Near-perfect Hashing of Large Word Sets". Software—Practice and Experience, vol. 19(10), 967-078, October 1989. John Wiley & Sons. - Douglas C. Schmidt, [GPERF: A Perfect Hash Function Generator](http://www.dre.vanderbilt.edu/~schmidt/PDF/gperf.pdf), C++ Report, SIGS, Vol. 10, No. 10, November/December, 1998. - Hans-Peter Lehmann, Thomas Mueller, Rasmus Pagh, Giulio Ermanno Pibiri, Peter Sanders, Sebastiano Vigna, Stefan Walzer, "Modern Minimal Perfect Hashing: A Survey", [arXiv](https://en.wikipedia.org/wiki/ArXiv_\(identifier\) "ArXiv (identifier)"):[2506\.06536](https://arxiv.org/abs/2506.06536), June 2025. Discusses post-1997 developments in the field. ## External links \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=14 "Edit section: External links")\] - [gperf](https://www.gnu.org/software/gperf/) is an [open source](https://en.wikipedia.org/wiki/Open_source "Open source") C and C++ perfect hash generator (very fast, but only works for small sets) - [Minimal Perfect Hashing (bob algorithm)](http://burtleburtle.net/bob/hash/perfect.html) by Bob Jenkins - [cmph](https://cmph.sourceforge.net/index.html): C Minimal Perfect Hashing Library, open source implementations for many (minimal) perfect hashes (works for big sets) - [Sux4J](http://sux.di.unimi.it/): open source monotone minimal perfect hashing in Java - [MPHSharp](https://web.archive.org/web/20130729211948/http://www.dupuis.me/node/9): perfect hashing methods in C\# - [BBHash](https://github.com/rizkg/BBHash): minimal perfect hash function in header-only C++ - [Perfect::Hash](https://github.com/rurban/Perfect-Hash), perfect hash generator in Perl that makes C code. Has a "prior art" section worth looking at. ![](https://en.wikipedia.org/wiki/Special:CentralAutoLogin/start?useformat=desktop&type=1x1&usesul3=1) Retrieved from "<https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&oldid=1318938338>" [Categories](https://en.wikipedia.org/wiki/Help:Category "Help:Category"): - [Hashing](https://en.wikipedia.org/wiki/Category:Hashing "Category:Hashing") - [Hash functions](https://en.wikipedia.org/wiki/Category:Hash_functions "Category:Hash functions") - [Search algorithms](https://en.wikipedia.org/wiki/Category:Search_algorithms "Category:Search algorithms") Hidden categories: - [CS1 maint: work parameter with ISBN](https://en.wikipedia.org/wiki/Category:CS1_maint:_work_parameter_with_ISBN "Category:CS1 maint: work parameter with ISBN") - [Articles with short description](https://en.wikipedia.org/wiki/Category:Articles_with_short_description "Category:Articles with short description") - [Short description is different from Wikidata](https://en.wikipedia.org/wiki/Category:Short_description_is_different_from_Wikidata "Category:Short description is different from Wikidata") - [Articles to be expanded from March 2023](https://en.wikipedia.org/wiki/Category:Articles_to_be_expanded_from_March_2023 "Category:Articles to be expanded from March 2023") - This page was last edited on 26 October 2025, at 22:28 (UTC). - Text is available under the [Creative Commons Attribution-ShareAlike 4.0 License](https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License "Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License"); additional terms may apply. By using this site, you agree to the [Terms of Use](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use "foundation:Special:MyLanguage/Policy:Terms of Use") and [Privacy Policy](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy "foundation:Special:MyLanguage/Policy:Privacy policy"). Wikipedia® is a registered trademark of the [Wikimedia Foundation, Inc.](https://wikimediafoundation.org/), a non-profit organization. - [Privacy policy](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy) - [About Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:About) - [Disclaimers](https://en.wikipedia.org/wiki/Wikipedia:General_disclaimer) - [Contact Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:Contact_us) - [Legal & safety contacts](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Legal:Wikimedia_Foundation_Legal_and_Safety_Contact_Information) - [Code of Conduct](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct) - [Developers](https://developer.wikimedia.org/) - [Statistics](https://stats.wikimedia.org/#/en.wikipedia.org) - [Cookie statement](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement) - [Mobile view](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&mobileaction=toggle_view_mobile) - [![Wikimedia Foundation](https://en.wikipedia.org/static/images/footer/wikimedia.svg)](https://www.wikimedia.org/) - [![Powered by MediaWiki](https://en.wikipedia.org/w/resources/assets/mediawiki_compact.svg)](https://www.mediawiki.org/) Search Toggle the table of contents Perfect hash function 6 languages [Add topic](https://en.wikipedia.org/wiki/Perfect_hash_function)
Readable Markdown
From Wikipedia, the free encyclopedia [![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Hash_table_4_1_1_0_0_0_0_LL.svg/250px-Hash_table_4_1_1_0_0_0_0_LL.svg.png)](https://en.wikipedia.org/wiki/File:Hash_table_4_1_1_0_0_0_0_LL.svg) A perfect hash function for the four names shown [![](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Hash_table_4_1_0_0_0_0_0_LL.svg/250px-Hash_table_4_1_0_0_0_0_0_LL.svg.png)](https://en.wikipedia.org/wiki/File:Hash_table_4_1_0_0_0_0_0_LL.svg) A minimal perfect hash function for the four names shown In [computer science](https://en.wikipedia.org/wiki/Computer_science "Computer science"), a **perfect hash function** h for a set S is a [hash function](https://en.wikipedia.org/wiki/Hash_function "Hash function") that maps distinct elements in S to a set of m integers, with no [collisions](https://en.wikipedia.org/wiki/Hash_collision "Hash collision"). In mathematical terms, it is an [injective function](https://en.wikipedia.org/wiki/Injective_function "Injective function"). Perfect hash functions may be used to implement a [lookup table](https://en.wikipedia.org/wiki/Lookup_table "Lookup table") with constant worst-case [access time](https://en.wikipedia.org/wiki/Access_time "Access time"). A perfect hash function can, as any [hash function](https://en.wikipedia.org/wiki/Hash_function "Hash function"), be used to implement [hash tables](https://en.wikipedia.org/wiki/Hash_table "Hash table"), with the advantage that no [collision resolution](https://en.wikipedia.org/wiki/Hash_table#Collision_resolution "Hash table") has to be implemented. In addition, if the keys are not in the data and if it is known that queried keys will be valid, then the keys do not need to be stored in the lookup table, saving space. Disadvantages of perfect hash functions are that S needs to be known for the construction of the perfect hash function. Non-dynamic perfect hash functions need to be re-constructed if S changes. For frequently changing S [dynamic perfect hash functions](https://en.wikipedia.org/wiki/Dynamic_perfect_hashing "Dynamic perfect hashing") may be used at the cost of additional space.[\[1\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-DynamicPerfectHashing-1) The space requirement to store the perfect hash function is in *O*(*n*) where *n* is the number of keys in the structure. The important performance parameters for perfect hash functions are the evaluation time, which should be constant, the construction time, and the representation size. A perfect hash function with values in a limited range can be used for efficient lookup operations, by placing keys from S (or other associated values) in a [lookup table](https://en.wikipedia.org/wiki/Lookup_table "Lookup table") indexed by the output of the function. One can then test whether a key is present in S, or look up a value associated with that key, by looking for it at its cell of the table. Each such lookup takes [constant time](https://en.wikipedia.org/wiki/Constant_time "Constant time") in the [worst case](https://en.wikipedia.org/wiki/Worst-case_complexity "Worst-case complexity").[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) With perfect hashing, the associated data can be read or written with a single access to the table.[\[3\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-3) ## Performance of perfect hash functions \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=2 "Edit section: Performance of perfect hash functions")\] The important performance parameters for perfect hashing are the representation size, the evaluation time, the construction time, and additionally the range requirement ![{\\displaystyle {\\frac {m}{n}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/d48d87468620ad6c70385ddd0d024577ccb559e1) (average number of buckets per key in the hash table).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) The evaluation time can be as fast as *O*(*1*), which is optimal.[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2)[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) The construction time needs to be at least *O*(*n*), because each element in S needs to be considered, and S contains n elements. This lower bound can be achieved in practice.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) The lower bound for the representation size depends on m and n. Let *m* = (1+ε) *n* and h a perfect hash function. A good approximation for the lower bound is ![{\\displaystyle \\log e-\\varepsilon \\log {\\frac {1+\\varepsilon }{\\varepsilon }}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/b02a088abd50352f229055b2573a6cb24e70ea05) Bits per element. For minimal perfect hashing, ε = 0, the lower bound is log e ≈ 1.44 bits per element.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) A perfect hash function for a specific set S that can be evaluated in constant time, and with values in a small range, can be found by a [randomized algorithm](https://en.wikipedia.org/wiki/Randomized_algorithm "Randomized algorithm") in a number of operations that is proportional to the size of S. The original construction of [Fredman, Komlós & Szemerédi (1984)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFFredmanKoml%C3%B3sSzemer%C3%A9di1984) uses a two-level scheme to map a set S of n elements to a range of *O*(*n*) indices, and then map each index to a range of hash values. The first level of their construction chooses a large prime p (larger than the size of the [universe](https://en.wikipedia.org/wiki/Universe_\(mathematics\) "Universe (mathematics)") from which S is drawn), and a parameter k, and maps each element x of S to the index ![{\\displaystyle g(x)=(kx{\\bmod {p}}){\\bmod {n}}.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/0eed5c339f42fdccc1685d8d3b1af928e2a3be01) If k is chosen randomly, this step is likely to have collisions, but the number of elements ni that are simultaneously mapped to the same index i is likely to be small. The second level of their construction assigns disjoint ranges of *O*(*ni*2) integers to each index i. It uses a second set of linear modular functions, one for each index i, to map each member x of S into the range associated with *g*(*x*).[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) As [Fredman, Komlós & Szemerédi (1984)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFFredmanKoml%C3%B3sSzemer%C3%A9di1984) show, there exists a choice of the parameter k such that the sum of the lengths of the ranges for the n different values of *g*(*x*) is *O*(*n*). Additionally, for each value of *g*(*x*), there exists a linear modular function that maps the corresponding subset of S into the range associated with that value. Both k, and the second-level functions for each value of *g*(*x*), can be found in [polynomial time](https://en.wikipedia.org/wiki/Polynomial_time "Polynomial time") by choosing values randomly until finding one that works.[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) The hash function itself requires storage space *O*(*n*) to store k, p, and all of the second-level linear modular functions. Computing the hash value of a given key x may be performed in constant time by computing *g*(*x*), looking up the second-level function associated with *g*(*x*), and applying this function to x. A modified version of this two-level scheme with a larger number of values at the top level can be used to construct a perfect hash function that maps S into a smaller range of length *n* + *o*(*n*).[\[2\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-inventor-2) A more recent method for constructing a perfect hash function is described by [Belazzougui, Botelho & Dietzfelbinger (2009)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFBelazzouguiBotelhoDietzfelbinger2009) as "hash, displace, and compress". Here a first-level hash function g is also used to map elements onto a range of r integers. An element *x* ∈ *S* is stored in the Bucket Bg(x).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) Then, in descending order of size, each bucket's elements are hashed by a hash function of a sequence of independent fully random hash functions (Φ1, Φ2, Φ3, ...), starting with Φ1. If the hash function does not produce any collisions for the bucket, and the resulting values are not yet occupied by other elements from other buckets, the function is chosen for that bucket. If not, the next hash function in the sequence is tested.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) To evaluate the perfect hash function *h*(*x*) one only has to save the mapping σ of the bucket index *g*(*x*) onto the correct hash function in the sequence, resulting in h(x) = Φσ(g(x)).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) Finally, to reduce the representation size, the (σ(i))0 ≤ i \< r are compressed into a form that still allows the evaluation in *O*(*1*).[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) This approach needs linear time in n for construction, and constant evaluation time. The representation size is in *O*(*n*), and depends on the achieved range. For example, with *m* = 1.23*n* [Belazzougui, Botelho & Dietzfelbinger (2009)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFBelazzouguiBotelhoDietzfelbinger2009) achieved a representation size between 3.03 bits/key and 1.40 bits/key for their given example set of 10 million entries, with lower values needing a higher computation time. The space lower bound in this scenario is 0.88 bits/key.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) | | | |---|---| | [![icon](https://upload.wikimedia.org/wikipedia/en/thumb/6/6c/Wiki_letter_w.svg/60px-Wiki_letter_w.svg.png)](https://en.wikipedia.org/wiki/File:Wiki_letter_w.svg) | This section **is missing information** about RecSplit & "fingerprinting" [recsplit paper](https://epubs.siam.org/doi/pdf/10.1137/1.9781611976007.14). Please expand the section to include this information. Further details may exist on the [talk page](https://en.wikipedia.org/wiki/Talk:Perfect_hash_function "Talk:Perfect hash function"). *(March 2023)* | ``` algorithm hash, displace, and compress is (1) Split S into buckets Bi := g−1({i})∩S,0 ≤ i < r (2) Sort buckets Bi in falling order according to size |Bi| (3) Initialize array T[0...m-1] with 0's (4) for all i ∈[r], in the order from (2), do (5) for l ← 1,2,... (6) repeat forming Ki ← {Φl(x)|x ∈ Bi} (6) until |Ki|=|Bi| and Ki∩{j|T[j]=1}= ∅ (7) let σ(i):= the successful l (8) for all j ∈ Ki let T[j]:= 1 (9) Transform (σi)0≤i<r into compressed form, retaining O(1) access. ``` The use of *O*(*n*) words of information to store the function of [Fredman, Komlós & Szemerédi (1984)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFFredmanKoml%C3%B3sSzemer%C3%A9di1984) is near-optimal: any perfect hash function that can be calculated in constant time requires at least a number of bits that is proportional to the size of S.[\[5\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-5) For minimal perfect hash functions the information theoretic space lower bound is ![{\\displaystyle \\log \_{2}e\\approx 1.44}](https://wikimedia.org/api/rest_v1/media/math/render/svg/0fd72ec3b460d6cf5434f1a0bb5bb5d24b4b2d15) bits/key.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) For perfect hash functions, it is first assumed that the range of h is bounded by n as *m* = (1+ε) *n*. With the formula given by [Belazzougui, Botelho & Dietzfelbinger (2009)](https://en.wikipedia.org/wiki/Perfect_hash_function#CITEREFBelazzouguiBotelhoDietzfelbinger2009) and for a [universe](https://en.wikipedia.org/wiki/Universe_\(mathematics\) "Universe (mathematics)") ![{\\displaystyle U\\supseteq S}](https://wikimedia.org/api/rest_v1/media/math/render/svg/16992fcab6da9089922e110403a580e2df030419) whose size \|*U*\| = *u* tends towards infinity, the space lower bounds is ![{\\displaystyle \\log \_{2}e-\\varepsilon \\log {\\frac {1+\\varepsilon }{\\varepsilon }}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/776f6c7e58c34f514e1be99b98abdf9f15e14e2a) bits/key, minus log(*n*) bits overall.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) ### Dynamic perfect hashing \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=7 "Edit section: Dynamic perfect hashing")\] Using a perfect hash function is best in situations where there is a frequently queried large set, S, which is seldom updated. This is because any modification of the set S may cause the hash function to no longer be perfect for the modified set. Solutions which update the hash function any time the set is modified are known as [dynamic perfect hashing](https://en.wikipedia.org/wiki/Dynamic_perfect_hashing "Dynamic perfect hashing"),[\[1\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-DynamicPerfectHashing-1) but these methods are relatively complicated to implement. ### Minimal perfect hash function \[[edit](https://en.wikipedia.org/w/index.php?title=Perfect_hash_function&action=edit&section=8 "Edit section: Minimal perfect hash function")\] A minimal perfect hash function is a perfect hash function that maps n keys to n consecutive integers – usually the numbers from 0 to *n* − 1 or from 1 to n. A more formal way of expressing this is: Let j and k be elements of some finite set S. Then h is a minimal perfect hash function if and only if *h*(*j*) = *h*(*k*) implies *j* = *k* ([injectivity](https://en.wikipedia.org/wiki/Injectivity "Injectivity")) and there exists an integer a such that the range of h is *a*..*a* + \|*S*\| − 1. It has been proven that a general purpose minimal perfect hash scheme requires at least ![{\\displaystyle \\log \_{2}e\\approx 1.44}](https://wikimedia.org/api/rest_v1/media/math/render/svg/0fd72ec3b460d6cf5434f1a0bb5bb5d24b4b2d15) bits/key.[\[4\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-CHD-4) Assuming that ![{\\displaystyle S}](https://wikimedia.org/api/rest_v1/media/math/render/svg/4611d85173cd3b508e67077d4a1252c9c05abca2) is a set of size ![{\\displaystyle n}](https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b) containing integers in the range ![{\\displaystyle \[1,2^{o(n)}\]}](https://wikimedia.org/api/rest_v1/media/math/render/svg/f0ac67d15f0cd602c935e60c92e1d2cf4bb68bff), it is known how to efficiently construct an explicit minimal perfect hash function from ![{\\displaystyle S}](https://wikimedia.org/api/rest_v1/media/math/render/svg/4611d85173cd3b508e67077d4a1252c9c05abca2) to ![{\\displaystyle \\{1,2,\\ldots ,n\\}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/4ebfec86b3f22a18f086275390917d5aaa2d8c22) that uses space ![{\\displaystyle n\\log \_{2}e+o(n)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/09277f1ba7d62f18c983de0af01dd3deea037948)bits and that supports constant evaluation time.[\[6\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-6) In practice, there are minimal perfect hashing schemes that use roughly 1.56 bits/key if given enough time.[\[7\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-RecSplit-7)[\[8\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-8) A hash function is k\-perfect if at most k elements from S are mapped onto the same value in the range. The "hash, displace, and compress" algorithm can be used to construct k\-perfect hash functions by allowing up to k collisions. The changes necessary to accomplish this are minimal, and are underlined in the adapted [pseudocode](https://en.wikipedia.org/wiki/Pseudocode "Pseudocode") below: ``` (4) for all i ∈[r], in the order from (2), do (5) for l ← 1,2,... (6) repeat forming Ki ← {Φl(x)|x ∈ Bi} (6) until |Ki|=|Bi| and Ki∩{j|T[j]=k}= ∅ (7) let σ(i):= the successful l (8) for all j ∈ Ki set T[j]←T[j]+1 ``` A minimal perfect hash function F is *order preserving* if keys are given in some order *a*1, *a*2, ..., *a**n* and for any keys *a**j* and *a**k*, *j* \< *k* implies *F*(*a**j*) \< F(*a**k*).[\[9\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-9) In this case, the function value is just the position of each key in the sorted ordering of all of the keys. A simple implementation of order-preserving minimal perfect hash functions with constant access time is to use an (ordinary) perfect hash function to store a lookup table of the positions of each key. This solution uses ![{\\displaystyle O(n\\log n)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/9d2320768fb54880ca4356e61f60eb02a3f9d9f1) bits, which is optimal in the setting where the comparison function for the keys may be arbitrary.[\[10\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-10) However, if the keys *a*1, *a*2, ..., *a**n* are integers drawn from a universe ![{\\displaystyle \\{1,2,\\ldots ,U\\}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/d2431655ee77a4033df95488cded81c131e07957), then it is possible to construct an order-preserving hash function using only ![{\\displaystyle O(n\\log \\log \\log U)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/760a3917c91c59e973214c6f49cc11d493cfbd92) bits of space.[\[11\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-11) Moreover, this bound is known to be optimal.[\[12\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-12) While well-dimensioned hash tables have amortized average O(1) time (amortized average constant time) for lookups, insertions, and deletion, most hash table algorithms suffer from possible worst-case times that take much longer. A worst-case O(1) time (constant time even in the worst case) would be better for many applications (including [network router](https://en.wikipedia.org/wiki/Network_router "Network router") and [memory caches](https://en.wikipedia.org/wiki/Memory_cache "Memory cache")).[\[13\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-davis-13): 41 Few hash table algorithms support worst-case O(1) lookup time (constant lookup time even in the worst case). The few that do include: perfect hashing; [dynamic perfect hashing](https://en.wikipedia.org/wiki/Dynamic_perfect_hashing "Dynamic perfect hashing"); [cuckoo hashing](https://en.wikipedia.org/wiki/Cuckoo_hashing "Cuckoo hashing"); [hopscotch hashing](https://en.wikipedia.org/wiki/Hopscotch_hashing "Hopscotch hashing"); and [extendible hashing](https://en.wikipedia.org/wiki/Extendible_hashing "Extendible hashing").[\[13\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-davis-13): 42–69 A simple alternative to perfect hashing, which also allows dynamic updates, is [cuckoo hashing](https://en.wikipedia.org/wiki/Cuckoo_hashing "Cuckoo hashing"). This scheme maps keys to two or more locations within a range (unlike perfect hashing which maps each key to a single location) but does so in such a way that the keys can be assigned one-to-one to locations to which they have been mapped. Lookups with this scheme are slower, because multiple locations must be checked, but nevertheless take constant worst-case time.[\[14\]](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_note-14) 1. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-DynamicPerfectHashing_1-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-DynamicPerfectHashing_1-1) Dietzfelbinger, Martin; [Karlin, Anna](https://en.wikipedia.org/wiki/Anna_Karlin "Anna Karlin"); [Mehlhorn, Kurt](https://en.wikipedia.org/wiki/Kurt_Mehlhorn "Kurt Mehlhorn"); Meyer auf der Heide, Friedhelm; Rohnert, Hans; [Tarjan, Robert E.](https://en.wikipedia.org/wiki/Robert_Tarjan "Robert Tarjan") (1994), "Dynamic perfect hashing: upper and lower bounds", *[SIAM Journal on Computing](https://en.wikipedia.org/wiki/SIAM_Journal_on_Computing "SIAM Journal on Computing")*, **23** (4): 738–761, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/S0097539791194094](https://doi.org/10.1137%2FS0097539791194094), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [1283572](https://mathscinet.ams.org/mathscinet-getitem?mr=1283572) . 2. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-1) [***c***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-2) [***d***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-3) [***e***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-inventor_2-4) [Fredman, Michael L.](https://en.wikipedia.org/wiki/Michael_Fredman "Michael Fredman"); [Komlós, János](https://en.wikipedia.org/wiki/J%C3%A1nos_Koml%C3%B3s_\(mathematician\) "János Komlós (mathematician)"); [Szemerédi, Endre](https://en.wikipedia.org/wiki/Endre_Szemer%C3%A9di "Endre Szemerédi") (1984), "Storing a Sparse Table with *O*(1) Worst Case Access Time", *[Journal of the ACM](https://en.wikipedia.org/wiki/Journal_of_the_ACM "Journal of the ACM")*, **31** (3): 538, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1145/828.1884](https://doi.org/10.1145%2F828.1884), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [0819156](https://mathscinet.ams.org/mathscinet-getitem?mr=0819156), [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [5399743](https://api.semanticscholar.org/CorpusID:5399743) 3. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-3)** [Lu, Yi](https://en.wikipedia.org/w/index.php?title=Yi_Lu_\(computer_scientist\)&action=edit&redlink=1 "Yi Lu (computer scientist) (page does not exist)"); [Prabhakar, Balaji](https://en.wikipedia.org/w/index.php?title=Balaji_Prabhakar&action=edit&redlink=1 "Balaji Prabhakar (page does not exist)"); [Bonomi, Flavio](https://en.wikipedia.org/w/index.php?title=Flavio_Bonomi&action=edit&redlink=1 "Flavio Bonomi (page does not exist)") (2006), "Perfect Hashing for Network Applications", *2006 IEEE International Symposium on Information Theory*, pp. 2774–2778, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1109/ISIT.2006.261567](https://doi.org/10.1109%2FISIT.2006.261567), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [1-4244-0505-X](https://en.wikipedia.org/wiki/Special:BookSources/1-4244-0505-X "Special:BookSources/1-4244-0505-X") , [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [1494710](https://api.semanticscholar.org/CorpusID:1494710) 4. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-1) [***c***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-2) [***d***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-3) [***e***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-4) [***f***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-5) [***g***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-6) [***h***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-7) [***i***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-8) [***j***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-9) [***k***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-10) [***l***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-CHD_4-11) Belazzougui, Djamal; Botelho, Fabiano C.; Dietzfelbinger, Martin (2009), ["Hash, displace, and compress"](https://cmph.sourceforge.net/papers/esa09.pdf) (PDF), [*Algorithms - ESA 2009*](https://cmph.sourceforge.net/papers/esa09.pdf) (PDF), [Lecture Notes in Computer Science](https://en.wikipedia.org/wiki/Lecture_Notes_in_Computer_Science "Lecture Notes in Computer Science"), vol. 5757, Berlin: Springer, pp. 682–693, [CiteSeerX](https://en.wikipedia.org/wiki/CiteSeerX_\(identifier\) "CiteSeerX (identifier)") [10\.1.1.568.130](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.568.130), [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1007/978-3-642-04128-0\_61](https://doi.org/10.1007%2F978-3-642-04128-0_61), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-3-642-04127-3](https://en.wikipedia.org/wiki/Special:BookSources/978-3-642-04127-3 "Special:BookSources/978-3-642-04127-3") , [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [2557794](https://mathscinet.ams.org/mathscinet-getitem?mr=2557794) . 5. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-5)** [Fredman, Michael L.](https://en.wikipedia.org/wiki/Michael_Fredman "Michael Fredman"); [Komlós, János](https://en.wikipedia.org/wiki/J%C3%A1nos_Koml%C3%B3s_\(mathematician\) "János Komlós (mathematician)") (1984), "On the size of separating systems and families of perfect hash functions", *[SIAM Journal on Algebraic and Discrete Methods](https://en.wikipedia.org/wiki/SIAM_Journal_on_Algebraic_and_Discrete_Methods "SIAM Journal on Algebraic and Discrete Methods")*, **5** (1): 61–68, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/0605009](https://doi.org/10.1137%2F0605009), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [0731857](https://mathscinet.ams.org/mathscinet-getitem?mr=0731857) . 6. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-6)** Hagerup, Torben; Tholey, Torsten (2001), ["Efficient Minimal Perfect Hashing in Nearly Minimal Space"](https://dx.doi.org/10.1007/3-540-44693-1_28), *STACS 2001*, Berlin, Heidelberg: Springer Berlin Heidelberg, pp. 317–326, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1007/3-540-44693-1\_28](https://doi.org/10.1007%2F3-540-44693-1_28), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-3-540-41695-1](https://en.wikipedia.org/wiki/Special:BookSources/978-3-540-41695-1 "Special:BookSources/978-3-540-41695-1") , retrieved 2023-11-12 `{{citation}}`: CS1 maint: work parameter with ISBN ([link](https://en.wikipedia.org/wiki/Category:CS1_maint:_work_parameter_with_ISBN "Category:CS1 maint: work parameter with ISBN")) 7. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-RecSplit_7-0)** Esposito, Emmanuel; Mueller Graf, Thomas; Vigna, Sebastiano (2020), "RecSplit: Minimal Perfect Hashing via Recursive Splitting", *2020 Proceedings of the Symposium on Algorithm Engineering and Experiments (ALENEX)*, [Proceedings](https://en.wikipedia.org/wiki/Proceedings "Proceedings"), pp. 175–185, [arXiv](https://en.wikipedia.org/wiki/ArXiv_\(identifier\) "ArXiv (identifier)"):[1910\.06416](https://arxiv.org/abs/1910.06416), [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/1.9781611976007.14](https://doi.org/10.1137%2F1.9781611976007.14) . 8. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-8)** [minimal-perfect-hash (GitHub)](https://github.com/iwiwi/minimal-perfect-hash) 9. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-9)** Jenkins, Bob (14 April 2009), "order-preserving minimal perfect hashing", in Black, Paul E. (ed.), [*Dictionary of Algorithms and Data Structures*](https://xlinux.nist.gov/dads/HTML/orderPreservMinPerfectHash.html), U.S. National Institute of Standards and Technology, retrieved 2013-03-05 10. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-10)** Fox, Edward A.; Chen, Qi Fan; Daoud, Amjad M.; Heath, Lenwood S. (July 1991), ["Order-preserving minimal perfect hash functions and information retrieval"](http://eprints.cs.vt.edu/archive/00000248/01/TR-91-01.pdf) (PDF), *ACM Transactions on Information Systems*, **9** (3), New York, NY, USA: ACM: 281–308, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1145/125187.125200](https://doi.org/10.1145%2F125187.125200), [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [53239140](https://api.semanticscholar.org/CorpusID:53239140) . 11. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-11)** Belazzougui, Djamal; Boldi, Paolo; [Pagh, Rasmus](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh"); Vigna, Sebastiano (November 2008), "Theory and practice of monotone minimal perfect hashing", *Journal of Experimental Algorithmics*, **16**, Art. no. 3.2, 26pp, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1145/1963190.2025378](https://doi.org/10.1145%2F1963190.2025378), [S2CID](https://en.wikipedia.org/wiki/S2CID_\(identifier\) "S2CID (identifier)") [2367401](https://api.semanticscholar.org/CorpusID:2367401) . 12. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-12)** Assadi, Sepehr; Farach-Colton, Martín; Kuszmaul, William (January 2023), ["Tight Bounds for Monotone Minimal Perfect Hashing"](https://dx.doi.org/10.1137/1.9781611977554.ch20), *Proceedings of the 2023 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA)*, Philadelphia, PA: Society for Industrial and Applied Mathematics, pp. 456–476, [arXiv](https://en.wikipedia.org/wiki/ArXiv_\(identifier\) "ArXiv (identifier)"):[2207\.10556](https://arxiv.org/abs/2207.10556), [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1137/1.9781611977554.ch20](https://doi.org/10.1137%2F1.9781611977554.ch20), [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-1-61197-755-4](https://en.wikipedia.org/wiki/Special:BookSources/978-1-61197-755-4 "Special:BookSources/978-1-61197-755-4") , retrieved 2023-04-27 `{{citation}}`: CS1 maint: work parameter with ISBN ([link](https://en.wikipedia.org/wiki/Category:CS1_maint:_work_parameter_with_ISBN "Category:CS1 maint: work parameter with ISBN")) 13. ^ [***a***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-davis_13-0) [***b***](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-davis_13-1) Timothy A. Davis. ["Chapter 5 Hashing"](https://www.cs.wm.edu/~tadavis/cs303/ch05sm.pdf): subsection "Hash Tables with Worst-Case O(1) Access" 14. **[^](https://en.wikipedia.org/wiki/Perfect_hash_function#cite_ref-14)** [Pagh, Rasmus](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh"); Rodler, Flemming Friche (2004), "Cuckoo hashing", *Journal of Algorithms*, **51** (2): 122–144, [doi](https://en.wikipedia.org/wiki/Doi_\(identifier\) "Doi (identifier)"):[10\.1016/j.jalgor.2003.12.002](https://doi.org/10.1016%2Fj.jalgor.2003.12.002), [MR](https://en.wikipedia.org/wiki/MR_\(identifier\) "MR (identifier)") [2050140](https://mathscinet.ams.org/mathscinet-getitem?mr=2050140) . - Richard J. Cichelli. *Minimal Perfect Hash Functions Made Simple*, Communications of the ACM, Vol. 23, Number 1, January 1980. - [Thomas H. Cormen](https://en.wikipedia.org/wiki/Thomas_H._Cormen "Thomas H. Cormen"), [Charles E. Leiserson](https://en.wikipedia.org/wiki/Charles_E._Leiserson "Charles E. Leiserson"), [Ronald L. Rivest](https://en.wikipedia.org/wiki/Ronald_L._Rivest "Ronald L. Rivest"), and [Clifford Stein](https://en.wikipedia.org/wiki/Clifford_Stein "Clifford Stein"). *[Introduction to Algorithms](https://en.wikipedia.org/wiki/Introduction_to_Algorithms "Introduction to Algorithms")*, Third Edition. MIT Press, 2009. [ISBN](https://en.wikipedia.org/wiki/ISBN_\(identifier\) "ISBN (identifier)") [978-0262033848](https://en.wikipedia.org/wiki/Special:BookSources/978-0262033848 "Special:BookSources/978-0262033848") . Section 11.5: Perfect hashing, pp. 267, 277–282. - Fabiano C. Botelho, [Rasmus Pagh](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh") and Nivio Ziviani. ["Perfect Hashing for Data Management Applications"](https://arxiv.org/abs/cs/0702159). - Fabiano C. Botelho and [Nivio Ziviani](https://en.wikipedia.org/wiki/Nivio_Ziviani "Nivio Ziviani"). ["External perfect hashing for very large key sets"](http://homepages.dcc.ufmg.br/~nivio/papers/cikm07.pdf). 16th ACM Conference on Information and Knowledge Management (CIKM07), Lisbon, Portugal, November 2007. - Djamal Belazzougui, Paolo Boldi, [Rasmus Pagh](https://en.wikipedia.org/wiki/Rasmus_Pagh "Rasmus Pagh"), and Sebastiano Vigna. ["Monotone minimal perfect hashing: Searching a sorted table with O(1) accesses"](https://web.archive.org/web/20140125080021/http://vigna.dsi.unimi.it/ftp/papers/MonotoneMinimalPerfectHashing.pdf). In Proceedings of the 20th Annual ACM-SIAM Symposium On Discrete Mathematics (SODA), New York, 2009. ACM Press. - Marshall D. Brain and Alan L. Tharp. "Near-perfect Hashing of Large Word Sets". Software—Practice and Experience, vol. 19(10), 967-078, October 1989. John Wiley & Sons. - Douglas C. Schmidt, [GPERF: A Perfect Hash Function Generator](http://www.dre.vanderbilt.edu/~schmidt/PDF/gperf.pdf), C++ Report, SIGS, Vol. 10, No. 10, November/December, 1998. - Hans-Peter Lehmann, Thomas Mueller, Rasmus Pagh, Giulio Ermanno Pibiri, Peter Sanders, Sebastiano Vigna, Stefan Walzer, "Modern Minimal Perfect Hashing: A Survey", [arXiv](https://en.wikipedia.org/wiki/ArXiv_\(identifier\) "ArXiv (identifier)"):[2506\.06536](https://arxiv.org/abs/2506.06536), June 2025. Discusses post-1997 developments in the field. - [gperf](https://www.gnu.org/software/gperf/) is an [open source](https://en.wikipedia.org/wiki/Open_source "Open source") C and C++ perfect hash generator (very fast, but only works for small sets) - [Minimal Perfect Hashing (bob algorithm)](http://burtleburtle.net/bob/hash/perfect.html) by Bob Jenkins - [cmph](https://cmph.sourceforge.net/index.html): C Minimal Perfect Hashing Library, open source implementations for many (minimal) perfect hashes (works for big sets) - [Sux4J](http://sux.di.unimi.it/): open source monotone minimal perfect hashing in Java - [MPHSharp](https://web.archive.org/web/20130729211948/http://www.dupuis.me/node/9): perfect hashing methods in C\# - [BBHash](https://github.com/rizkg/BBHash): minimal perfect hash function in header-only C++ - [Perfect::Hash](https://github.com/rurban/Perfect-Hash), perfect hash generator in Perl that makes C code. Has a "prior art" section worth looking at.
Shard152 (laksa)
Root Hash17790707453426894952
Unparsed URLorg,wikipedia!en,/wiki/Perfect_hash_function s443