Comment
Author: Admin | 2025-04-28
Table 2 at h2(53) Next: 100. h1(100) = 1. Next: 67. h1(67) = 1. But 100 is already there at 1. We place 67 in table 1 & 100 in table 2 Next: 105. h1(105) = 6. But 50 is already there at 6. We place 105 in table 1 & 50 in table 2 at h2(50) = 4. Now 53 has been displaced. h1(53) = 9. 75 displaced: h2(75) = 6.Next: 3. h1(3) = 3.Next: 36. h1(36) = 3. h2(3) = 0.Next: 39. h1(39) = 6. h2(105) = 9. h1(100) = 1. h2(67) = 6. h1(75) = 9. h2(53) = 4. h1(50) = 6. h2(39) = 3.Here, the new key 39 is displaced later in the recursive calls to place 105, which it displaced.Implementation: Below is the implementation of Cuckoo hashing C++ // C++ program to demonstrate working of Cuckoo// hashing.#include// upper bound on number of elements in our set#define MAXN 11// choices for position#define ver 2// Auxiliary space bounded by a small multiple// of MAXN, minimizing wastageint hashtable[ver][MAXN];// Array to store possible positions for a keyint pos[ver];/* function to fill hash table with dummy value * dummy value: INT_MIN * number of hashtables: ver */void initTable(){ for (int j=0; jMAXN; j++) for (int i=0; iver; i++) hashtable[i][j] = INT_MIN;}/* return hashed value for a key * function: ID of hash function according to which key has to hashed * key: item to be hashed */int hash(int function, int key){ switch (function) { case 1: return key%MAXN; case 2:
Add Comment