Skip to main content
Engineering LibreTexts

11.6: Open Addressing continued

  • Page ID
    34699
  • b) Quadratic Probing We look for i2‘th slot in i’th iteration.

    let hash(x) be the slot index computed using hash function.  
    If slot hash(x) % S is full, then we try (hash(x) + 1*1) % S
    If (hash(x) + 1*1) % S is also full, then we try (hash(x) + 2*2) % S
    If (hash(x) + 2*2) % S is also full, then we try (hash(x) + 3*3) % S
    ..................................................
    ..................................................

    c) Double Hashing We use another hash function hash2(x) and look for i*hash2(x) slot in i’th rotation.

    let hash(x) be the slot index computed using hash function.  
    If slot hash(x) % S is full, then we try (hash(x) + 1*hash2(x)) % S
    If (hash(x) + 1*hash2(x)) % S is also full, then we try (hash(x) + 2*hash2(x)) % S
    If (hash(x) + 2*hash2(x)) % S is also full, then we try (hash(x) + 3*hash2(x)) % S
    ..................................................
    ..................................................

    Geeks for Geeks provides a video covering these concepts.

     

    Comparison of above three:
    Linear probing has the best cache performance but suffers from clustering. One more advantage of Linear probing is easy to compute.

    Quadratic probing lies between the two in terms of cache performance and clustering.

    Double hashing has poor cache performance but no clustering. Double hashing requires more computation time as two hash functions need to be computed.

    "Hashing | Set 3 (Open Addressing)" by Pulkit Goel is licensed under CC BY-SA 4.0