ArticleslgStudy

computer science

Extendible hashing

Extendible 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 Extendible hashing rather than just read about it. In short: Extendible hashing is a type of hash system which treats a hash as a bit string and uses a trie for bucket lookup. Because of the hierarchical nature of the system, re-hashing is an incremental operation (done one bucket at a time, as needed).

Extendible hashing — main illustration
Extendible hashing — illustration

Key takeaways

  • Extendible 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 Extendible hashing to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Extendible hashing from memory before moving on to harder problems.

Reference excerpt

Extendible hashing is a type of hash system which treats a hash as a bit string and uses a trie for bucket lookup. Because of the hierarchical nature of the system, re-hashing is an incremental operation (done one bucket at a time, as needed). This means that time-sensitive applications are less affected by table growth than by standard full-table rehashes. Extendible hashing was described by Ronald Fagin in 1979. Practically all modern filesystems use either extendible hashing or B-trees. In particular, the Global File System, GPFS, ZFS, and the SpadFS filesystem use extendible hashing.

Example Assume that the hash function h(k) returns a string of bits. The first i bits of each string will be used as indices to figure out where they will go in the "directory" (hash table), where i is the smallest number such that the index of every item in the table is unique. Keys to be used: h(k1)=100100h(k2)=010110h(k3)=110110 Let's assume that for this particular example, the bucket size is 1. The first two keys to be inserted, k1 and k2, can be distinguished by the most significant bit, and would be inserted into the table as follows:

Now, if k3 were to be hashed to the table, it wouldn't be enough to distinguish all three keys by one bit (because both k3 and k1 have 1 as their leftmost bit). Also, because the bucket size is one, the table would overflow. Because comparing the first two most significant bits would give each key a unique location, the directory size is doubled as follows:

And so now k1 and k3 have a unique location, being distinguished by the first two leftmost bits. Because k2 is in the top half of the table, both 00 and 01 point to it because there is no other key to compare to that begins with a 0. The above example is from Fagin et al. (1979).

Further detail h(k4)=011110 Now, k4 needs to be inserted, and it has the first two bits as 01..(1110), and using a 2 bit depth in the directory, this maps from 01 to Bucket A. Bucket A is full (max size 1), so it must be split; because there is more than one pointer to Bucket A, there is no need to increase the directory size. What is needed is information about:

The key size that maps the directory (the global depth), and The key size that has previously mapped the bucket (the local depth) In order to distinguish the two action cases:

Doubling the directory when a bucket becomes full Creating a new bucket, and re-distributing the entries between the old and the new bucket Examining the initial case of an extendible hash structure, if each directory entry points to one bucket, then the local depth should be equal to the global depth. The number of directory entries is equal to 2global depth, and the initial number of buckets is equal to 2local depth. Thus if global depth = local depth = 0, then 20 = 1, so an initial directory of one pointer to one bucket. Back to the two action cases; if the bucket is full:

If the local depth is equal to the global depth, then there is only one pointer to the bucket, and there is no other directory pointers that can map to the bucket, so the directory must be doubled. If the local depth is less than the global depth, then there exists more than one pointer from the directory to the bucket, and the bucket can be split.

Key 01 points to Bucket A, and Bucket A's local depth of 1 is less than the directory's global depth of 2, which means keys hashed to Bucket A have only used a 1 bit prefix (i.e. 0), and the bucket needs to have its contents split using keys 1 + 1 = 2 bits in length; in general, for any local depth d where d is less than D, the global depth, then d must be incremented after a bucket split, and the new d used as the number of bits of each entry's key to redistribute the entries of the former bucket into the new buckets.

Now, h(k4)=011110 is tried again, with 2 bits 01.., and now key 01 points to a new bucket but there is still ⁠k2⁠ in it (h(k2)=010110 and also begins with 01). If ⁠k2⁠ had been 000110, with key 00, there would have been no problem, because ⁠k2⁠ would have remained in the new bucket A' and bucket D would have been empty. (This would have been the most likely case by far when buckets are of greater size than 1 and the newly split buckets would be exceedingly unlikely to overflow, unless all the entries were all rehashed to one bucket again. But just to emphasize the role of the depth information, the example will be pursued logically to the end.) So Bucket D needs to be split, but a check of its local depth, which is 2, is the same as the global depth, which is 2, so the directory must be split again, in order to hold keys of sufficient detail, e.g. 3 bits.

Bucket D needs to split due to being full. As D's local depth = the global depth, the directory must double to increase bit detail of keys. Global depth has incremented after directory split to 3. The new entry ⁠k4⁠ is rekeyed with global depth 3 bits and ends up in D which has local depth 2, which can now be incremented to 3 and D can be split to D' and E. The contents of the split bucket D, ⁠k2⁠, has been re-keyed with 3 bits, and it ends up in D'. K4 is retried and it ends up in E which has a spare slot.

Now, h(k2)=010110 is in D and h(k4)=011110 is tried again, with 3 bits 011.., and it points to bucket D which already contains ⁠k2⁠ so is full; D's local depth is 2 but now the global depth is 3 after the directory doubling, so now D can be split into bucket's D' and E, the contents of D, ⁠k2⁠ has its h(k2) retried with a new global depth bitmask of 3 and ⁠k2⁠ ends up in D', then the new entry ⁠k4⁠ is retried with h(k4) bitmasked using the new global depth bit count of 3 and this gives 011 which now points to a new bucket E which is empty. So ⁠k4⁠ goes in Bucket E.

Example implementation Below is the extendible hashing algorithm in Python, with the disc block / memory page association, caching and consistency issues removed. Note a problem exists if the depth exceeds the bit size of an integer, because then doubling of the directory or splitting of a bucket won't allow entries to be rehashed to different buckets. The code uses the least significant bits, which makes it more efficient to expand the table, as the entire directory can be copied as one block (Ramakrishnan & Gehrke (2003)).

Python example

Notes

See also Trie Hash table Stable hashing Consistent hashing Linear hashing

… excerpt ends here. Continue reading the full article.

Illustrations

Extendible hashing illustration
Extendible hashing illustration
Extendible hashing illustration
Extendible hashing illustration
Extendible hashing illustration

Worked examples

Example 1 — a first encounter with Extendible hashing

Start with the simplest possible case. Write down what Extendible 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 Extendible 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 Extendible 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 Extendible hashing

In research
Extendible 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 Extendible 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
Extendible 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 Extendible 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 “Extendible hashing” →

How to study Extendible hashing in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Extendible 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 Extendible hashing out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Extendible hashing in simple terms?

Extendible hashing is a type of hash system which treats a hash as a bit string and uses a trie for bucket lookup. Because of the hierarchical nature of the system, re-hashing is an incremental operation (done one bucket at a time, as needed).

Why does Extendible 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 Extendible 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 Extendible hashing.

Tags

  • Hashing
  • Search algorithms

Keep exploring