TheHingineer

  • Data Structures & Algorithms


  • DSA Part-1

  • DSA Part-2

  • DSA Part-3

  • DSA Part-4

  • DSA Part-5

  • Collision Resolution: Separate Chaining Method

    Separate Chaining (Open Hashing) collision handle karne ki sabse robust aur widely used technique hai (Java ke HashMap aur C++ ke unordered_map me natively implemented). Is method me hash table ka har slot ek pointer hold karta hai jo ek Linked List ko point karta hai.

    Table Slots:
    [0] ---> NULL
    [1] ---> NULL
    [2] ---> [ 22 | Next ] ---> [ 42 | Next ] ---> [ 92 | NULL ]
    [3] ---> [ 13 | NULL ]
    [4] ---> NULL
    [5] ---> [ 25 | Next ] ---> [ 75 | NULL ]
    

    Working Principle

    Jab bhi koi naya element key insert hota hai, toh hash function index = h(key) calculate karta hai. Fir us index par bani linked list ke starting ya end me naya node attach kar diya jata hai. Agar multiple keys same index par hash hoti hain, toh wo seamlessly linked list me chain hoti chali jaati hain.

    Load Factor (α) and Complexity Analysis

    Hash table performance Load Factor (α) par depend karti hai:

    Load Factor (α) = n / m   (n = Total Keys, m = Number of Slots)
    • Average Case Time Complexity: O(1 + α) – Agar hash function uniformly distribute kare aur α <= 0.75 rahe, toh search, insert aur delete O(1) constant time me execute hote hain.
    • Worst Case Time Complexity: O(n) – Agar saari keys bad hash function ki wajah se single slot par chain ho jayein (pure linked list ban jaye).

    Separate Chaining vs Open Addressing Comparison

    Feature Separate Chaining Open Addressing
    Storage Location Linked lists outside table Directly inside table slots
    Table Size Limit Never full (α can be > 1) Cannot exceed table capacity (α < 1)
    Deletion Ease Simple standard linked list node deletion Complex (requires tombstone/deleted markers)
    Cache Performance Poor cache locality (nodes scattered in heap) Excellent cache performance (contiguous array)

    Is topic ke saath Data Structures & Algorithms (DSA) ka complete syllabus finish hota hai! Agle subject me hum start karenge Design & Analysis of Algorithms (DAA).

    Scroll to Top