Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 326 Hashing Richard Anderson (instead of Martin Tompa)

Similar presentations


Presentation on theme: "CSE 326 Hashing Richard Anderson (instead of Martin Tompa)"— Presentation transcript:

1 CSE 326 Hashing Richard Anderson (instead of Martin Tompa)

2 Chaining review kH(k) A B C D E F G H I J K 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 H(k) = k mod 17

3 Open address hashing Store all elements in table If a cell is occupied, try another cell. Linear probing, try cells H(k), H(k) + 1 mod m, H(k) + 2 mod m,..

4 Open Address Hashing kH(k) A532 B417 C916 D757 E13 F66 G437 H6716 I883 J362 K406 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 H(k) = k mod 17 0 1 2A 3I 4J 5 6C 7B 8D 9F 10K 11 12 13E 14 15 16H

5 Open address hashing Lookup (K) { p = H(K); loop { if (A[p] is empty) return false; if (A[p] == K) return true; p = (p + 1) mod m; }

6 Open address hashing issues Issues: Clumping Cost per operation Deletion

7 Double hashing Use separate hash functions for the first probe and the collision resolution H 1 (k), H 1 (k) + H 2 (k) mod m, H 1 (k) + 2H 2 (k) mod m, H 1 (k) + 3H 2 (k) mod m,...

8 Double hashing example monthdayH 1 (k) A B C D E F G H I J K 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 H 1 (k) = day mod 17 H 2 (k) = month

9 Double hashing vs. Single hashing Load factor  cost per operation Single hashing Double hashing 

10 Trade offs between chaining and open addressing Chaining Open Addressing

11 Hash Functions Function Efficient Uniform mapping to range Avoids systematic collisions

12 Hashing strings String Suppose

13 Fact: So:


Download ppt "CSE 326 Hashing Richard Anderson (instead of Martin Tompa)"

Similar presentations


Ads by Google