ArticleslgStudy

computer science

Dynamic perfect hashing

Dynamic perfect hashing is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Dynamic perfect hashing rather than just read about it. In short: In computer science, dynamic perfect hashing is a programming technique for resolving collisions in a hash table data structure. While more memory-intensive than its hash table counterparts, this technique is useful for situations where fast queries, insertions, and deletions must be made on a large set of elements.

Key takeaways

  • Dynamic perfect hashing belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Dynamic perfect hashing to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Dynamic perfect hashing from memory before moving on to harder problems.

Reference excerpt

In computer science, dynamic perfect hashing is a programming technique for resolving collisions in a hash table data structure. While more memory-intensive than its hash table counterparts, this technique is useful for situations where fast queries, insertions, and deletions must be made on a large set of elements.

Details

Static case

FKS scheme

The problem of optimal static hashing was first solved in general by Fredman, Komlós and Szemerédi. In their 1984 paper, they detail a two-tiered hash table scheme in which each bucket of the (first-level) hash table corresponds to a separate second-level hash table. Keys are hashed twice—the first hash value maps to a certain bucket in the first-level hash table; the second hash value gives the position of that entry in that bucket's second-level hash table. The second-level table is guaranteed to be collision-free (i.e. perfect hashing) upon construction. Consequently, the look-up cost is guaranteed to be O(1) in the worst-case. In the static case, we are given a set with a total of x entries, each one with a unique key, ahead of time. Fredman, Komlós and Szemerédi pick a first-level hash table with size s=2(x−1) buckets. To construct, x entries are separated into s buckets by the top-level hashing function, where s=2(x−1). Then for each bucket with k entries, a second-level table is allocated with k2 slots, and its hash function is selected at random from a universal hash function set so that it is collision-free (i.e. a perfect hash function) and stored alongside the hash table. If the hash function randomly selected creates a table with collisions, a new hash function is randomly selected until a collision-free table can be guaranteed. Finally, with the collision-free hash, the k entries are hashed into the second-level table. The quadratic size of the k2 space ensures that randomly creating a table with collisions is infrequent and independent of the size of k, providing linear amortized construction time. Although each second-level table requires quadratic space, if the keys inserted into the first-level hash table are uniformly distributed, the structure as a whole occupies expected O(n) space, since bucket sizes are small with high probability. The first-level hash function is specifically chosen so that, for the specific set of x unique key values, the total space T used by all the second-level hash tables has expected O(n) space, and more specifically T<s+4⋅x. Fredman, Komlós and Szemerédi showed that given a universal hashing family of hash functions, at least half of those functions have that property.

Dynamic case Dietzfelbinger et al. present a dynamic dictionary algorithm that, when a set of n items is incrementally added to the dictionary, membership queries always run in constant time and therefore O(1) worst-case time, the total storage required is O(n) (linear), and O(1) expected amortized insertion and deletion time (amortized constant time). In the dynamic case, when a key is inserted into the hash table, if its entry in its respective subtable is occupied, then a collision is said to occur and the subtable is rebuilt based on its new total entry count and randomly selected hash function. Because the load factor of the second-level table is kept low 1/k, rebuilding is infrequent, and the amortized expected cost of insertions is O(1). Similarly, the amortized expected cost of deletions is O(1). Additionally, the ultimate sizes of the top-level table or any of the subtables is unknowable in the dynamic case. One method for maintaining expected O(n) space of the table is to prompt a full reconstruction when a sufficient number of insertions and deletions have occurred. By results due to Dietzfelbinger et al., as long as the total number of insertions or deletions exceeds the number of elements at the time of last construction, the amortized expected cost of insertion and deletion remain O(1) with full rehashing taken into consideration. The implementation of dynamic perfect hashing by Dietzfelbinger et al. uses these concepts, as well as lazy deletion, and is shown in pseudocode below.

Pseudocode implementation

Locate function Locate(x) is j := h(x) if (position hj(x) of subtable Tj contains x (not deleted)) return (x is in S) end if else return (x is not in S) end else end

Insert During the insertion of a new entry x at j, the global operations counter, count, is incremented. If x exists at j, but is marked as deleted, then the mark is removed. If x exists at j or at the subtable Tj, and is not marked as deleted, then a collision is said to occur and the jth bucket's second-level table Tj is rebuilt with a different randomly selected hash function hj.

function Insert(x) is count = count + 1; if (count > M) FullRehash(x); end if else j := h(x); if (Position hj(x) of subtable Tj contains x) if (x is marked deleted) remove the delete marker; end if end if else bj = bj + 1; if (bj <= mj) if position hj(x) of Tj is empty store x in position hj(x) of Tj; end if else Put all unmarked elements of Tj in list Lj; Append x to list Lj; bj = length of Lj; repeat hj = randomly chosen function in Hsj; until hj is injective on the elements of Lj; for all y on list Lj store y in position hj(y) of Tj; end for end else end if else mj = 2 * max{1, mj}; sj = 2 * mj * (mj - 1); if the sum total of all sj ≤ 32 * M2 / s(M) + 4 * M Allocate sj cells for Tj; Put all unmarked elements of Tj in list Lj; Append x to list Lj; bj = length of Lj; repeat hj = randomly chosen function in Hsj; until hj is injective on the elements of Lj; for all y on list Lj store y in position hj(y) of Tj; end for end if else FullRehash(x); end else end else end else end else end

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Dynamic perfect hashing

Start with the simplest possible case. Write down what Dynamic perfect hashing claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Dynamic perfect hashing before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Dynamic perfect hashing ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Dynamic perfect hashing

In research
Dynamic perfect hashing appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Dynamic perfect hashing in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Dynamic perfect hashing is common in secondary-school and first-year university syllabi. It links to neighbouring topics Hashing, Search algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Dynamic perfect hashing outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Dynamic perfect hashing” →

How to study Dynamic perfect hashing in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Dynamic perfect hashing means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Dynamic perfect hashing out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Dynamic perfect hashing in simple terms?

In computer science, dynamic perfect hashing is a programming technique for resolving collisions in a hash table data structure. While more memory-intensive than its hash table counterparts, this technique is useful for situations where fast queries, insertions, and deletions must be made on a larg…

Why does Dynamic perfect hashing matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Dynamic perfect hashing?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Dynamic perfect hashing.

Tags

  • Hashing
  • Search algorithms

Keep exploring