Download presentation
Presentation is loading. Please wait.
1
A Hash Table with Chaining
A hash table with size m = 13, h(k) = k mod 13, Store keys: 18, 41, 90, 12, 36, 28, 54, 38, 25, 10 A 1 2 3 4 5 6 7 8 9 10 11 12 54 28 41 18 10 36 25 38 12 90
2
A Hash Table with Chaining
A hash table with size m = 11, Key Values: A S E R C H I N G X M P L Hash value: 1 8 5 7 3 9 2 A 1 2 3 4 5 6 7 8 9 10 L A A A M X N C E P E E G R H S I
3
Linear Probing m = 11, h(k) = k mod 11, Keys stored in the hash table:
21, 26, 5, 13, 37, 16, 15 37 1 2 3 4 5 6 7 8 9 10 13 26 5 37 21 A
4
Linear Probing m = 11, h(k) = k mod 11, Keys stored in the hash table:
21, 26, 5, 13, 37, 16, 15 16 1 2 3 4 5 6 7 8 9 10 13 26 5 37 16 21 A
5
Linear Probing m = 11, h(k) = k mod 11, Keys stored in the hash table:
21, 26, 5, 13, 37, 16, 15 15 1 2 3 4 5 6 7 8 9 10 13 26 5 37 16 15 21 A
6
Linear Probing m = 19, Key values: Hash values: 1 5 18 3 8 9 14 7 13
C H I N G X M P L Hash values: 1 5 18 3 8 9 14 7 13 16 12 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A E A
7
Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6
C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C E G H I N R A
8
Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6
C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C E E G H I N R A
9
Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6
C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C E E G H I X N R A
10
Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6
C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C A E E G H I X L M N P R A
11
Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6
C H I N G E X A M P L E hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C A E E G H I X E L M N P R A
12
Linear Probing Inserting the element (k,x)
Insert at T[h(k)] if empty else probe until space found Searching for the element (k,x) Look in T[h(k)] and all succeeding elements until there is a space or element is found Removing the element (k,x) Difficult!
13
Linear Probing Insert E then X; h(E) = 5, E -> 10
1 2 3 4 5 6 7 8 9 10 A 11 12 13 14 15 16 17 18 S E R C H I N G M P L Insert E then X; h(E) = 5, E -> 10 h(X) = 5, X -> 11 Now remove the E and search for X
14
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G X M P L hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A E A
15
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 H 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E A R A
16
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I N H R A
17
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E N H R A
18
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E X N H R A
19
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E X N H R A
20
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E X N A H R A
21
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 P 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E M G A I E X N A H R A
22
Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A P C E M G A I E L X N A H R A
23
Double Hashing N = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3
R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A P C E M G A I E L X N A H E R A
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.