Download presentation
Presentation is loading. Please wait.
Published byΚίρκη Αντωνόπουλος Modified over 5 years ago
1
Hash Tables: Associative Containers with Constant Time Operations --- On Average
Consider the problem of computing the frequency of words in a text file . . .
2
This is this and that is that, said Carl.
Hash Tables: Associative Containers with Constant Time Operations --- On Average Consider the problem of computing the frequency of words in a text file . . . This is this and that is that, said Carl. Carl 1 that 2 is 2 said 1 this 2 and 1
3
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 2 3 4 5 ‘this’ 6 Hash Table
4
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 h is a hash function 2 3 4 h 5 ‘this’ 6 Hash Table
5
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 2 3 4 Initialize the frequency h 5 1 ‘this’ 6 Hash Table
6
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 Another word 2 ‘is’ 3 4 5 1 ‘this’ 6 Hash Table
7
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 2 h ‘is’ 3 4 5 1 ‘this’ 6 Hash Table
8
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 2 h ‘is’ 3 1 4 5 1 ‘this’ 6 Hash Table
9
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 2 ‘is’ 3 1 4 Another ‘this’ 5 1 ‘this’ 6 Hash Table
10
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 2 ‘is’ 3 1 4 h 5 1 ‘this’ 6 Hash Table
11
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency 1 2 ‘is’ 3 1 4 Increment the frequency h 5 2 ‘this’ 6 Hash Table
12
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency Another word ‘and’ 1 2 ‘is’ 3 1 4 5 2 ‘this’ 6 Hash Table
13
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 ‘is’ h 3 1 4 5 2 ‘this’ 6 Hash Table
14
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 ‘is’ h 3 1 4 5 2 ‘this’ 6 1 Hash Table
15
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 ‘is’ 3 1 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
16
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 h ‘is’ 3 1 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
17
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 1 h ‘is’ 3 1 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
18
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 1 Another ‘is’ ‘is’ 3 1 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
19
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 1 h ‘is’ 3 1 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
20
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 1 h ‘is’ Increment the frequency 3 2 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
21
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 1 ‘is’ 3 2 Another ‘that’ 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
22
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 1 h ‘is’ 3 2 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
23
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 Increment the frequency 2 2 h ‘is’ 3 2 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
24
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 2 ‘is’ 3 2 Another word ‘said’ 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
25
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 2 h ‘is’ 3 2 Collision! Another word ‘said’ 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
26
This is this and that is that, said Carl. Strings Frequency
Hash Tables: Associative Containers with Constant Time Operations --- On Average This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 2 ‘is’ 3 2 Collision! Another word ‘said’ 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
27
How can collisions be resolved?
This is this and that is that, said Carl. Strings Frequency ‘and’ 1 2 2 ‘is’ 3 2 Another word ‘said’ 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
28
How can collisions be resolved?
First of all, store the keys in the table. . . Strings Frequency ‘and’ 1 2 2 ‘is’ 3 2 Another word ‘said’ 4 ‘that’ 5 2 ‘this’ 6 1 Hash Table
29
How can collisions be resolved?
First of all, store the keys in the table. . . Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 Another word ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
30
Collision is detected if HashTable[h(word)].Key word
Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
31
Collision is detected if HashTable[h(word)].Key word
e.g., HashTable[h(‘said’)].Key = ‘is’ ‘said’ Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
32
Consider h(word) to be just the starting position for searching the table for word.
Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
33
Consider h(word) to be just the starting position for searching the table for word.
E.g., start the search for ‘said’ at position 3, since h(‘said’) = 3. Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
34
Continue search by going through some sequence of positions.
Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
35
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
36
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
37
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ Empty slot, so put it there 4 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
38
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ Empty slot, so put it there 4 said ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
39
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ 1 2 that 2 ‘is’ 3 is 2 word = ‘said’ And initialize frequency 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
40
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
41
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
42
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, . . . Strings Key Frequency ‘and’ word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
43
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, h(word) + 3, . . . Strings Key Frequency ‘and’ word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
44
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, h(word) + 3, 0, 1, . . . Strings Key Frequency ‘and’ Wrap around word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
45
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, h(word) + 3, 0, 1, . . . Strings Key Frequency ‘and’ Empty slot, so insert it here word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
46
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, h(word) + 3, 0, 1, . . . Strings Key Frequency ‘and’ carl word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
47
Continue search by going through some sequence of positions.
E.g, h(word), h(word) + 1, h(word) + 2, h(word) + 3, 0, 1, . . . Strings Key Frequency ‘and’ And initialize frequency carl 1 word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
48
} Strings Key Frequency
Continue search by going through some sequence of positions. E.g, h(word), h(word) + 1, h(word) + 2, h(word) + 3, 0, 1, . . . This method of collision resolution is called . . . } Strings Key Frequency ‘and’ carl 1 word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
49
} Strings Key Frequency
Continue search by going through some sequence of positions. E.g, h(word), h(word) + 1, h(word) + 2, h(word) + 3, 0, 1, . . . “linear probing” (one form of “open addressing”) } Strings Key Frequency ‘and’ carl 1 word = ‘carl’ 1 2 that 2 ‘is’ 3 is 2 ‘said’ 4 said 1 ‘that’ 5 this 2 ‘this’ 6 and 1 Hash Table
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.