1 / 58

Hashing in Action

Hashing in Action. Nattee Niparnan. Operation. Insert Depends on Find Delete Depends on Find, also. Find. Find a room that should contain the value. Simple Hash. Room index. Hash Function. Name. Trying to add. Add Alice. 1. Hash Function. Alice. Add Alice. 1. Hash Function.

avari
Télécharger la présentation

Hashing in Action

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hashing in Action Nattee Niparnan

  2. Operation • Insert • Depends on Find • Delete • Depends on Find, also

  3. Find • Find a room that should contain the value

  4. Simple Hash Room index Hash Function Name

  5. Trying to add

  6. Add Alice 1 Hash Function Alice

  7. Add Alice 1 Hash Function Alice

  8. Add Peter 9 Hash Function Peter

  9. Add Bob 2 Hash Function Bob

  10. Find Vicky 7 Hash Function Vicky

  11. Add Vicky 7 Hash Function Vicky

  12. Collision Resolution

  13. Two approach • Separate chaining • Create another “space” for the collision • Need more memory • Open addressing • Try to squeeze in another room • Does not need more memory • Deletion problem

  14. Separate chaining • Try adding • The new 3 guys will collide with “Alice”

  15. Add Adam Adam Collide!! 1 Hash Function

  16. We use “LinkedList” as the storage Adam Alice 1 Bob Hash Function Vicky Peter

  17. Add Adam as a new node Adam Alice Adam 1 Bob Hash Function Vicky Peter

  18. Add Able as a new node Able Alice Adam 1 Bob Hash Function Able Vicky Peter

  19. Open Addressing • Find another room • Linear Probing (LP) • Quadratic Probing (QP) • Double Hashing (DH)

  20. Open Addressing Mechanism • Each time a collision occur, • Count the number of collision • “ColCount” • Instead of using Hash1(x) as the room index • Use instead “Hash1(x) + F(ColCount)” • F(ColCount) is the open addressing function

  21. Linear Probing • Use next room • F(ColCount) = ColCount;

  22. Adding Adam in LP

  23. Add Adam in LP Adam Collide!! 1 Hash Function

  24. Add Adam in LP Adam 2 Hash Function Update!!

  25. Add Adam in LP Adam 2 Collide!! Again Hash Function

  26. Add Adam in LP Adam 3 Hash Function Update!!

  27. Add Adam in LP Adam 3 Hash Function Free Space

  28. Adding Able in LP

  29. Add Able in LP Able Collide!! 1 Hash Function

  30. Add Able in LP Able 2 Hash Function Update!!

  31. Add Able in LP Able 2 Collide!! Again Hash Function

  32. Add Able in LP Able 3 Hash Function Update!!

  33. Add Able in LP Able 3 Hash Function Collide Again

  34. Add Able in LP Able 4 Hash Function Free Space Update!!

  35. Quadratic Probing • Jump by square • F(ColCount) = ColCount * ColCount;

  36. Adding Adam in QP

  37. Add Adam in QP Adam Collide!! 1 Hash Function

  38. Add Adam in QP Adam 2 Hash Function Update!!

  39. Add Adam in QP Adam 2 Collide!! Again Hash Function

  40. Add Adam in QP Adam 5 Hash Function Update!!

  41. Add Adam in QP Adam 5 Hash Function Free Space

  42. Adding Able in QP

  43. Add Able in QP Able Collide!! 1 Hash Function

  44. Add Able in QP Able 2 Hash Function Update!!

  45. Add Able in QP Able 2 Collide!! Again Hash Function

  46. Add Able in QP Able 5 Hash Function Update!!

  47. Add Able in QP Able 5 Hash Function Collide Again!!

  48. Add Able in QP Able 10 Hash Function Update!!

  49. Add Able in QP Able 5 Hash Function Free Space

  50. Double Hashing • Jump by another hash function • F(ColCount) = ColCount * Hash2(x);

More Related