CSE 326 Hashing - PowerPoint PPT Presentation

About This Presentation
Title:

CSE 326 Hashing

Description:

CSE 326 Hashing Richard Anderson (instead of Martin Tompa) Chaining review Open address hashing Store all elements in table If a cell is occupied, try another cell. – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 14
Provided by: Richar1148
Category:
Tags: cse | collision | hashing | space

less

Transcript and Presenter's Notes

Title: CSE 326 Hashing


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

2
Chaining review
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
k H(k)
A
B
C
D
E
F
G
H
I
J
K
H(k) k mod 17
Collect twelve birthdays from students and hash
into the table with chaining
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
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0
1
2 A
3 I
4 J
5
6 C
7 B
8 D
9 F
10 K
11
12
13 E
14
15
16 H
k H(k)
A 53 2
B 41 7
C 91 6
D 75 7
E 13 13
F 6 6
G 43 7
H 67 16
I 88 3
J 36 2
K 40 6
H(k) k mod 17
Collect twelve birthdays from students and hash
into the table with chaining
Step through example Emphasize the growing
regions
5
Open address hashing
Lookup (K) p H(K) loop if (Ap is
empty) return false if (Ap 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
  • H1(k), H1(k) H2(k) mod m, H1(k)
    2H2(k) mod m, H1(k)
    3H2(k) mod m , . . .

Return to earlier slide to update the access code
8
Double hashing example
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
month day H1(k)
A
B
C
D
E
F
G
H
I
J
K
H1(k) day mod 17
H2(k) month
Collect twelve birthdays (month and day) from
students and hash into the table with
chaining WRITE MONTHS AS NUMBERS
9
Double hashing vs.Single hashing
Single
  • Load factor a, cost per operation
  • Single hashing
  • Double hashing

Double
a
10
Trade offs between chaining and open addressing
Chaining Open Addressing
Space Time Deletions Coding complexity High load
factor
11
Hash Functions
  • Function
  • Efficient
  • Uniform mapping to range
  • Avoids systematic collisions

12
Hashing strings
  • String
  • Suppose

13
  • Fact
  • So
Write a Comment
User Comments (0)
About PowerShow.com