Hash Tables - Chapter 4 Flashcards
A blank is a data structure that stores unordered items by mapping (or hashing) each item to a location in an array (or vector).
hash table
A hash table’s main advantage is that searching (or inserting / removing) an item may require only blank, in contrast to O(N) for searching a list or to O(log N) for binary search.
O(1)
In a hash table, an item’s blank is the value used to map to an index.
key
For all items that might possibly be stored in the hash table, every key is ideally blank, so that the hash table’s algorithms can search for a specific item by that key.
unique
Each hash table array element is called a blank
bucket
A hash function computes a bucket index from the blank.
item’s key
A common hash function uses the blank, which computes the integer remainder when dividing two numbers.
modulo operator %
A hash table’s operations of insert, remove, and search each use the blank to determine an item’s bucket
hash function
The approach for a hash table algorithm determining whether a cell is blank depends on the implementation. For example, if items are simply non-negative integers, empty can be represented as -1.
empty
More commonly, items are each an object with multiple fields (name, age, etc.), in which case each hash table array element may be a pointer. Using pointers, empty can be represented as blank.
null
A blank occurs when an item being inserted into a hash table maps to the same bucket as an existing item in the hash table.
collision
Blank is a collision resolution technique where each bucket has a list of items (so bucket 5’s list would become 55, 75).
Chaining
Blank is a collision resolution technique where collisions are resolved by looking for an empty bucket elsewhere in the table (so 75 might be stored in bucket 6).
Open addressing
Blank handles hash table collisions by using a list for each bucket, where each list may store multiple items that map to the same bucket
Chaining
The blank operation first uses the item’s key to determine the bucket, and then inserts the item in that bucket’s list
insert
Searching also first determines the bucket, and then searches the bucket’s blank
list
A hash table with blank handles a collision by starting at the key’s mapped bucket, and then linearly searches subsequent buckets until an empty bucket is found.
linear probing
Actually, linear probing distinguishes two types of empty buckets
empty-since-start
empty-after-removal
An blank bucket has been empty since the hash table was created.
empty-since-start
An blank bucket had an item removed that caused the bucket to now be empty
empty-after-removal
Using linear probing, a hash table blank algorithm uses the item’s key to determine the initial bucket, linearly probes (or checks) each bucket, and inserts the item in the next empty bucket (the empty kind doesn’t matter).
insert
Using linear probing, a hash table blank algorithm uses the sought item’s key to determine the initial bucket. The algorithm probes each bucket until either a matching item is found, an empty-since-start bucket is found, or all buckets have been probed. If the item is found, the item is removed, and the bucket is marked empty-after-removal.
remove
Note that if the algorithm encounters an blank bucket, the algorithm keeps probing, because the sought item may have been placed in a subsequent bucket before this bucket’s item was removed.
empty-after-removal
A hash table with blank handles a collision by starting at the key’s mapped bucket, and then quadratically searches subsequent buckets until an empty bucket is found.
quadratic probing
If an item’s mapped bucket is H, the formula blank is used to determine the item’s index in the hash table.
(H + c1 * i + c2* i^2) mod (tablesize)
Each time an empty bucket is not found, i is incremented by 1. Iterating through sequential i values to obtain the desired table index is called the blank.
probing sequence