ArticleslgStudy

science

Open addressing

Open addressing is a 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 Open addressing rather than just read about it. In short: Open addressing, or closed hashing, is a method of collision resolution in hash tables. With this method a hash collision is resolved by probing, or searching through alternative locations in the array (the probe sequence) until either the target record is found, or an unused array slot is found, which indicates that there is no such key in the table.

Open addressing — main illustration
Open addressing — illustration

Key takeaways

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

Reference excerpt

Open addressing, or closed hashing, is a method of collision resolution in hash tables. With this method a hash collision is resolved by probing, or searching through alternative locations in the array (the probe sequence) until either the target record is found, or an unused array slot is found, which indicates that there is no such key in the table. Well-known probe sequences include:

Linear probing in which the interval between probes is fixed — often set to 1. Quadratic probing in which the interval between probes increases linearly (hence, the indices are described by a quadratic function). Double hashing in which the interval between probes is fixed for each record but is computed by another hash function. The main trade offs between these methods are that linear probing has the best cache performance but is most sensitive to clustering, while double hashing has poor cache performance but exhibits virtually no clustering; quadratic probing falls in between in both areas. Double hashing can also require more computation than other forms of probing. Some open addressing methods, such as Hopscotch hashing, Robin Hood hashing, last-come-first-served hashing and cuckoo hashing move existing keys around in the array to make room for the new key. This gives better maximum search times than the methods based on probing. A critical influence on performance of an open addressing hash table is the load factor; that is, the proportion of the slots in the array that are used. As the load factor increases towards 100%, the number of probes that may be required to find or insert a given key rises dramatically. Once the table becomes full, probing algorithms may even fail to terminate. Even with good hash functions, load factors are normally limited to 80%. A poor hash function can exhibit poor performance even at very low load factors by generating significant clustering, especially with the simplest linear addressing method. Generally typical load factors with most open addressing methods are 50%, while separate chaining typically can use up to 100%.

Example pseudocode The following pseudocode is an implementation of an open addressing hash table with linear probing and single-slot stepping, a common approach that is effective if the hash function is good. Each of the lookup, set and remove functions use a common internal function find_slot to locate the array slot that either does or should contain a given key.

record pair { key, value, occupied flag (initially unset) } var pair slot[0], slot[1], ..., slot[num_slots - 1]

function find_slot(key) i := hash(key) modulo num_slots // search until we either find the key, or find an empty slot. while (slot[i] is occupied) and (slot[i].key ≠ key) i := (i + 1) modulo num_slots return i

function lookup(key) i := find_slot(key) if slot[i] is occupied // key is in table return slot[i].value else // key is not in table return not found

function set(key, value) i := find_slot(key) if slot[i] is occupied // we found our key slot[i].value := value return if the table is almost full rebuild the table larger (note 1) i := find_slot(key) mark slot[i] as occupied slot[i].key := key slot[i].value := value

note 1 Rebuilding the table requires allocating a larger array and recursively using the set operation to insert all the elements of the old array into the new larger array. It is common to increase the array size exponentially, for example by doubling the old array size. function remove(key) i := find_slot(key) if slot[i] is unoccupied return // key is not in the table mark slot[i] as unoccupied j := i loop (note 2) j := (j + 1) modulo num_slots if slot[j] is unoccupied exit loop k := hash(slot[j].key) modulo num_slots // determine if k lies cyclically in (i,j] // i ≤ j: | i..k..j | // i > j: |.k..j i....| or |....j i..k.| if i ≤ j if (i < k) and (k ≤ j) continue loop else if (k ≤ j) or (i < k) continue loop mark slot[i] as occupied slot[i].key := slot[j].key slot[i].value := slot[j].value mark slot[j] as unoccupied i := j

note 2 For all records in a cluster, there must be no vacant slots between their natural hash position and their current position (else lookups will terminate before finding the record). At this point in the pseudocode, i is a vacant slot that might be invalidating this property for subsequent records in the cluster. j is such a subsequent record. k is the raw hash where the record at j would naturally land in the hash table if there were no collisions. This test is asking if the record at j is invalidly positioned with respect to the required properties of a cluster now that i is vacant. Another technique for removal is simply to mark the slot as deleted. However this eventually requires rebuilding the table simply to remove deleted records. The methods above provide O(1) updating and removal of existing records, with occasional rebuilding if the high-water mark of the table size grows. The O(1) remove method above is only possible in linearly probed hash tables with single-slot stepping. In the case where many records are to be deleted in one operation, marking the slots for deletion and later rebuilding may be more efficient.

Performance Assuming an ideal hash function (one that uniformly distributes all elements of the universe), and a random choice of elements from the universe, the performance of the linear probing method is:

E U n = 1 2 ( 1 + 1 1 − α ) + Θ ( 1 m ) {\displaystyle EU_{n}={\frac {1}{2}}\left(1+{\frac {1}{1-\alpha }}\right)+\Theta ({\frac {1}{m}})}

… excerpt ends here. Continue reading the full article.

Illustrations

Open addressing: Hash collision resolved by linear probing (interval=1).
Hash collision resolved by linear probing (interval=1).

Worked examples

Example 1 — a first encounter with Open addressing

Start with the simplest possible case. Write down what Open addressing claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In 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 Open addressing 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 Open addressing 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 Open addressing

In research
Open addressing appears in 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 Open addressing 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
Open addressing is common in secondary-school and first-year university syllabi. It links to neighbouring topics Hashing, so understanding it makes those chapters shorter.
In everyday life
Look for Open addressing 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.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Open addressing in 20 minutes

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

Frequently asked questions

What is Open addressing in simple terms?

Open addressing, or closed hashing, is a method of collision resolution in hash tables. With this method a hash collision is resolved by probing, or searching through alternative locations in the array (the probe sequence) until either the target record is found, or an unused array slot is found, w…

Why does Open addressing matter?

Because it connects several 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 Open addressing?

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 Open addressing.

Tags

  • Hashing

Keep exploring