Skip to content
Think & Reflect · Q1

Q.Suppose a list has more than one element whose modulo division results in same remainder value. In such situations, what kind of hashing may be useful?

Puducherry CbseNCERTSubjective· 2mImportance★★★★★est
100% · 17/17 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

When multiple elements produce the same hash index (a collision), separate chaining (or open hashing) is the most commonly used technique to store all colliding elements in a linked list at that index.


Hashing maps keys to array indices using a hash function. When you use modulo division — say hash(key) = key % table_size — different keys can produce the same remainder. For example, if the table size is 10, both 23 and 43 hash to index 3. This is a collision.

The question asks which hashing technique handles collisions when modulo division is the hash function. Two main families exist:

Separate Chaining (Open Hashing)

Each slot in the hash table holds a linked list (or another dynamic structure like a Python list). When a collision occurs, the new element is simply appended to the list at that index.

Why it works well here:

  • No limit on the number of elements that can hash to the same index.
  • Simple to implement: insert, search, and delete operations just traverse the chain.
  • The table never "fills up" in the traditional sense; performance degrades gracefully as chains grow longer.

Example: Hash table of size 5, inserting keys 12, 22, 32 (all hash to index 2):

IndexChain
0→
1→
2→ 12 → 22 → 32
3→
4→

Open Addressing (Closed Hashing)

When a collision occurs, the algorithm probes for the next available slot in the table itself using a sequence: linear probing ((h + i) % size), quadratic probing ((h + i²) % size), or double hashing. All elements live directly in the array, no auxiliary structures.

Trade-offs:

  • The table can fill up (load factor α ≤ 1).
  • Clustering can degrade performance (especially with linear probing).
  • Deletion is more complex (requires tombstones or rehashing).

Tip

Separate chaining is the default choice in most real-world hash tables (Python's dict, Java's HashMap before Java 8) because it is robust and easy to reason about. Open addressing is preferred when memory locality matters or you want to avoid pointer overhead.

Watch out

A common mistake is to confuse the hash function (modulo division) with the collision resolution strategy (chaining or probing). Modulo division causes collisions; chaining or open addressing resolves them.


Python Example: Separate Chaining

class HashTable:
    def __init__(self, size=10):
        self.size = size …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.