Download presentation
Presentation is loading. Please wait.
1
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 4 h2( x) = x mod 8 n = 0 Two hash functions reflect this size 1 Original hash table size = 4 2 3 Initial cutoff set to 0
2
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 4 h2( x) = x mod 8 n = 0 1 2 3
3
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(12) = 12 mod 4 = 0 h2( x) = x mod 8 n = 0 12 Use h1(x) as long as its >= cutoff 1 2 3
4
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(17) = 17 mod 4 = 1 h2( x) = x mod 8 n = 0 12 1 17 2 3
5
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(10) = 10 mod 4 = 2 h2( x) = x mod 8 n = 0 12 1 17 2 10 3
6
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 6) = 6 mod 4 = 2 h2( x) = x mod 8 n = 0 12 1 17 2 10 6 3
7
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(24) = 24 mod 4 = 0 h2( x) = x mod 8 n = 0 12 24 1 17 2 10 6 3
8
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 n = 0 12 Overflow, so 24 1 17 2 10 6 3
9
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 n = 0 12 Overflow, so 24 1) add chained block 1 17 2 10 6 14 3
10
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 12 Overflow, so 24 n = 1 2) increment cutoff value 1 17 2 10 6 14 3
11
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 12 Overflow, so 24 n = 1 3) split bucket 0 into two buckets 1 17 2 10 6 14 3 4
12
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 12 Overflow, so 24 n = 1 4) rehash values in bucket 0 using h2(x) 1 17 2 10 6 14 3 4
13
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 24 Overflow, so n = 1 4) rehash values in bucket 0 using h2(x) 1 17 2 10 6 14 3 4 12
14
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 5) = 5 mod 4 = 1 h2( x) = x mod 8 24 n = 1 1 17 5 2 10 6 14 3 4 12
15
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(20) = 20 mod 4 = 0 h2( x) = x mod 8 24 h1(20) < cutoff, so … n = 1 1 17 5 2 10 6 14 3 4 12
16
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(20) = 20 mod 4 = 0 h2(20) = 20 mod 8 = 4 24 h1(20) < cutoff, so use h2(20) n = 1 1 17 5 2 10 6 14 3 4 12 20
17
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so n = 1 1) add chained block 1 17 5 1 2 10 6 14 3 4 12 20
18
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so 2) increment cutoff value 3) split bucket 1 1 17 5 1 n = 2 2 10 6 14 3 4 12 20 5
19
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so 4) rehash values in bucket 1 using h2(x) 1 17 5 1 n = 2 2 10 6 14 3 4 12 20 5
20
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so 4) rehash values in bucket 1 using h2(x) 1 17 1 n = 2 2 10 6 14 3 4 12 20 5
21
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(13) = 13 mod 4 = 1 h2( x) = x mod 8 h1(13) < cutoff, so … 24 1 17 1 n = 2 2 10 6 14 3 4 12 20 5
22
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(13) = 13 mod 4 = 1 h2(13) = 13 mod 8 = 5 24 h1(13) < cutoff, so use h2(13) 1 17 1 n = 2 2 10 6 14 3 4 12 20 5 13
23
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 7) = 7 mod 4 = 3 h2( x) = x mod 8 24 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 5 13
24
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( x) = x mod 8 24 h1(4) < cutoff, so … 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 5 13
25
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 h1(4) < cutoff, so use h2(4) 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 5 13
26
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 1) add chained block 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 4 5 13
27
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 2) increment cutoff value 3) split bucket 2 1 17 1 2 10 6 14 n = 3 3 7 4 12 20 4 5 13 6
28
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 4) rehash values in bucket 2 using h2(x) 1 17 1 2 10 6 14 n = 3 3 7 4 12 20 4 5 13 6
29
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 4) rehash values in bucket 2 using h2(x) 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14
30
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2( x) = x mod 8 24 h1(22) < cutoff, so … 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14
31
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 h1(22) < cutoff, so use h2(22) 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14
32
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 1) add chained block 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14 22
33
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 2) increment cutoff value 3) split bucket 3 1 17 1 2 10 3 7 n = 4 4 12 20 4 5 13 6 14 22 7
34
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 4) rehash values in bucket 3 using h2(x) 1 17 1 2 10 3 7 n = 4 4 12 20 4 5 13 6 14 22 7
35
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 4) rehash values in bucket 3 using h2(x) 1 17 1 2 10 3 n = 4 4 12 20 4 5 13 6 14 22 7
36
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Since cutoff = original hash table size 1 17 1 2 10 3 n = 4 4 12 20 4 5 13 6 14 22 7
37
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 8 h2( x) = x mod 16 24 Since cutoff = original hash table size 1) set table size to 8, modifying h1(x) and h2(x) 1 17 1 2 10 3 n = 4 4 12 20 4 5 13 6 14 22 7
38
Linear Hashing Example
Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 8 h2( x) = x mod 16 n = 0 Since cutoff = original hash table size 24 2) reset cutoff to 0 1 17 1 2 10 3 4 12 20 4 5 13 6 14 22 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.