Hashing and Hash Tables
- 89Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
89 questions
- 1Searching through randomly positioned books one by one until finding a target is called_____.
Hint
This search method examines items sequentially.
Answer
linear search
- 2The process of converting a key to a fixed-size value is called_____.
Hint
This process transforms input data into a compact numerical result.
Answer
hashing
- 3The result produced by the hashing process is called a_____.
Hint
It is the fixed-size value obtained from a key.
Answer
hash
- 4A data structure that stores key/value pairs and uses hashing to locate values is a_____.
Hint
It organizes values in array slots according to hashed keys.
Answer
hash table
- 5In a hash table, values are stored in an array of_____.
Hint
These are the positions of the underlying array.
Answer
slots
- 6In the library analogy, the book title is the_____, the book is the value, and the library is the array.
Hint
It is the piece of information used to locate an associated value.
Answer
key
- 7The function that takes a key as input, performs computations, and returns its hash is a_____.
Hint
It is the computational tool used during hashing.
Answer
hash function
- 8For an array with m slots, a hash function should return an index from_____.
Hint
Array indexing begins at zero and ends one position before the capacity.
Answer
0 to m-1
- 9The variable m represents the number of_____in a hash table.
Hint
It is the table's capacity.
Answer
slots
- 10A hash function that always returns the same hash for the same key is_____.
Hint
Its output does not vary when the input is unchanged.
Answer
deterministic
- 11If a hash function produced different results for the same key during insertion and searching, the correct position could not be found because the function would not be_____.
Hint
The same input must consistently produce the same output.
Answer
deterministic
- 12A simple hash function can calculate a string's hash by summing the characters'_____codes and taking the result modulo m.
Hint
These numerical codes represent characters.
Answer
ASCII
- 13For the key "inside code", the ASCII sum used in the example is_____.
Hint
This is the sum before applying modulo 30.
Answer
1079
- 14Using the example function with the key "inside code" and m=30 produces the hash_____.
Hint
Compute 1079 modulo 30.
Answer
29
- 15A hash table used as a phone agenda can use a person's name as the key and the person's_____as the value.
Hint
This is the contact information being retrieved.
Answer
phone number
- 16In a word counter, the key is a word and the value is an integer representing its number of_____.
Hint
The counter records how often each word appears.
Answer
occurrences
- 17In a dictionary implemented with a hash table, the key is a word and the value is its_____.
Hint
This explains the meaning of the word.
Answer
definition
- 18Hash tables can also be used in_____to support applications such as secure data processing.
Hint
This field studies techniques for protecting information.
Answer
cryptography
- 19The condition that keys in a hash table cannot be repeated is called key_____.
Hint
Each key should identify at most one entry.
Answer
uniqueness
- 20Unlike keys, hash table values_____be unique.
Hint
Multiple keys may legitimately refer to equal values.
Answer
do not need to
- 21A key must be_____so that its hash remains consistent throughout its use in a hash table.
Hint
It must not change after it is used to determine a position.
Answer
immutable
- 22An array or set cannot normally be used as a key because these objects are_____.
Hint
Their contents can change after creation.
Answer
mutable
- 23Integers, strings, and tuples are examples of types that can be used as keys because they are generally_____.
Hint
Their relevant contents do not change after creation.
Answer
immutable
- 24A mutable object can be used as a hash table value because values are not passed to the_____.
Hint
Only keys determine locations.
Answer
hash function
- 25When two different keys produce the same hash and therefore the same index, the event is called a_____.
Hint
Two keys compete for one location.
Answer
collision
- 26The collision-handling method that stores multiple entries in a linked list at one slot is called_____.
Hint
Each occupied slot contains a chain of nodes.
Answer
separate chaining
- 27With separate chaining, each node in a collision list contains a_____pair.
Hint
Storing only values would not identify which value belongs to which key.
Answer
key/value
- 28If three keys hash to index 13 under separate chaining, slot 13 contains a linked list of length_____.
Hint
Each colliding key contributes one node.
Answer
3
- 29When searching a separate-chaining list after a collision, the key must be stored in each node to identify the correct_____.
Hint
The key is used to select the associated data.
Answer
value
- 30The collision-handling technique that keeps at most one value in each spot and searches for another spot when necessary is_____.
Hint
Entries remain directly in the table rather than in linked lists.
Answer
open addressing
- 31In open addressing, searching alternative spots for an insertion or lookup is called_____.
Hint
The algorithm examines candidate positions one after another.
Answer
probing
- 32The probing strategy that checks consecutive positions until it finds an empty slot is_____.
Hint
The search advances one array position at a time.
Answer
linear probing
- 33If linear probing finds the hashed slot occupied, it checks the next slot and continues until it finds an_____one.
Hint
The target position must be available for insertion.
Answer
empty
- 34Even with open addressing, storing the_____is necessary to identify the requested value after collisions.
Hint
The value alone does not reveal which original key produced it.
Answer
key
- 35Hashing into m possible indices cannot avoid collisions for infinitely many possible keys because of the_____principle.
Hint
More objects than containers force two objects into the same container.
Answer
Pigeonhole
- 36A hash function that maps a fixed set of keys to slots without any collisions is called a_____.
Hint
It is collision-free for the specific key set.
Answer
perfect hash function
- 37Perfect hashing is possible when the number of keys does not exceed the table's number of_____and the key set is known.
Hint
There must be at least one available position per key.
Answer
spots
- 38A hash function that concentrates most keys in a small subset of slots is considered a_____hash function.
Hint
Uneven output probabilities create many collisions.
Answer
bad
- 39A good hash function distributes keys as_____as possible over the available hash values.
Hint
Its outputs should be spread rather than concentrated.
Answer
evenly
- 40If a hash function produces values from 0 to 4 most of the time despite having 30 possible indices, it will create_____collisions.
Hint
Many keys are being forced into only five positions.
Answer
a lot of
- 41A hash function is also considered better when it is computationally_____.
Hint
The function should not require excessive computation.
Answer
efficient
- 42A table with 10 spots and 50 keys has an average of_____elements per spot.
Hint
Divide 50 elements by 10 spots.
Answer
5
- 43When too many keys are stored in too few slots, the fundamental problem is a lack of_____.
Hint
A larger range of available positions would reduce crowding.
Answer
space
- 44Creating a larger table and reinserting all existing pairs into it is called_____.
Hint
The table is rebuilt using a new capacity.
Answer
rehashing
- 45A common rehashing strategy is to create a new table with_____the number of spots.
Hint
The new capacity is often multiplied by two.
Answer
double
- 46The ratio used to measure how full a hash table is is n/m, where n is the number of inserted elements and m is the number of_____.
Hint
The denominator represents table capacity.
Answer
slots
- 47For n=21 elements and m=30 slots, the fullness ratio n/m is_____.
Hint
Divide 21 by 30.
Answer
0.7
- 48In open addressing, the ratio n/m cannot exceed_____because each slot stores at most one element.
Hint
The table is full when every slot is occupied.
Answer
1
- 49In separate chaining, the ratio n/m can exceed 1 because one slot can store_____elements.
Hint
A linked list can contain several nodes at one index.
Answer
multiple
- 50The maximum allowed value of n/m before rehashing is called the_____.
Hint
It determines when the table should be resized.
Answer
load factor
- 51If the load factor is 0.75, a table rehashes as soon as n/m_____0.75.
Hint
The threshold is crossed rather than merely reached.
Answer
exceeds
- 52With 100 slots and a load factor of 0.75, inserting element number_____triggers rehashing.
Hint
The first 75 elements produce a ratio of 0.75.
Answer
76
- 53A load factor of 0.75 is described as a generally good_____value.
Hint
It is commonly chosen when no special tradeoff is required.
Answer
default
- 54Reducing the load factor generally improves time efficiency by reducing collisions but decreases_____efficiency.
Hint
More unused slots are allocated.
Answer
space
- 55Increasing the load factor improves space efficiency but usually reduces_____efficiency because collisions increase.
Hint
More collisions require more searching.
Answer
time
- 56The simple ASCII-sum hash function gives the same hash to "abc" and "acb" because it is insensitive to character_____.
Hint
Both strings contain the same characters, only arranged differently.
Answer
order
- 57For strings of at most 20 alphabetical characters, the maximum ASCII sum under the example function is_____.
Hint
Multiply 20 by the maximum alphabetical ASCII code, 122.
Answer
2440
- 58If the maximum possible hash is 2440, all table slots after index 2440 are_____to the hash function.
Hint
No key can map to those positions.
Answer
useless
- 59Rehashing cannot reduce collisions caused by a maximum hash of 2440 because the new slots remain_____.
Hint
The hash function still cannot reach their indices.
Answer
empty
- 60In a hash table implementation using separate chaining, each_____contains the key, value, and pointer to the next node.
Hint
It is the basic element of a linked list.
Answer
Node
- 61The linked-list structure used for each separate-chaining slot contains only the_____.
Hint
This pointer identifies the first node.
Answer
head
- 62The three linked-list operations needed by the implementation are insertion, searching, and_____.
Hint
This operation removes a node with a specified key.
Answer
deletion
- 63Inserting a node at the beginning of a linked list makes the new node's next pointer refer to the current_____.
Hint
The old first node becomes second.
Answer
head
- 64A linked-list search returns the node whose key equals the input key; if no such node exists, it returns_____.
Hint
This indicates the absence of a result.
Answer
null
- 65When deleting a node from a linked list, the implementation skips the node whose key matches the target by changing the previous node's_____pointer.
Hint
This pointer determines the following node in the list.
Answer
next
- 66A hash table implementation stores its number of slots in a field called the_____.
Hint
It describes how many positions the table has.
Answer
capacity
- 67The number of elements currently stored in a hash table is tracked by its_____.
Hint
It begins at zero and increases when new nodes are inserted.
Answer
size
- 68During rehashing, the implementation doubles capacity, resets size, creates new slots, and then_____the old key/value pairs.
Hint
The entries must be placed according to the new table size.
Answer
reinserts
- 69When inserting a key that already exists, the hash table should_____its value rather than add a second key.
Hint
The existing entry remains, but its associated data changes.
Answer
update
- 70When a new key/value pair is added, the hash table increments its_____.
Hint
The number of stored nodes has increased.
Answer
size
- 71When a key/value pair is successfully deleted, the hash table_____its size.
Hint
The number of stored elements decreases by one.
Answer
decrements
- 72If a table becomes too empty, it may rehash by reducing its number of slots to save_____.
Hint
The goal is to avoid maintaining unnecessary capacity.
Answer
space
- 73Inserting at the beginning of a linked list has time complexity_____because no nodes need to be traversed.
Hint
The operation takes constant time.
Answer
O(1)
- 74Searching a linked list of length l for a key has time complexity_____.
Hint
The search may inspect every node in the list.
Answer
O(l)
- 75Deleting a node from a linked list has time complexity_____because the target may require traversal.
Hint
Its cost depends on the list length.
Answer
O(l)
- 76The hash function is treated as running in_____time with respect to the number of elements in the table.
Hint
Its runtime is independent of table size.
Answer
O(1)
- 77In the best case, no collisions cause each separate-chaining list to have length 0 or_____.
Hint
At most one node occupies a slot in this case.
Answer
1
- 78In the worst case, all n nodes are in one linked list, making search time_____.
Hint
The list length equals the total number of elements.
Answer
O(n)
- 79With a good hash function and suitable rehashing, the length of an individual collision list usually remains under some_____.
Hint
The list is kept reasonably short on average.
Answer
constant
- 80Because linked-list searches are usually short in practice, searching for a node in a separate-chaining table is_____on average.
Hint
The expected list length is treated as bounded.
Answer
O(1)
- 81Although an individual rehash can cost O(n), insertion is O(1)_____because rehashing occurs infrequently.
Hint
This analysis averages occasional expensive operations over many cheap ones.
Answer
amortized
- 82In the average case, lookup, getting a value, and deletion each have time complexity_____.
Hint
Each hashes once and usually searches a short list.
Answer
O(1)
- 83Hash table insertion, lookup, retrieval, and deletion can all take_____time in the worst case.
Hint
This occurs when many or all entries must be searched.
Answer
O(n)
- 84The space complexity of a hash table is_____because it stores n nodes and a number of slots proportional to n.
Hint
Both major sources of space grow linearly.
Answer
O(n)
- 85The two-sum problem asks for the indices of two array elements whose sum is_____.
Hint
This is the target sum named in the problem.
Answer
k
- 86A brute-force solution that tests all pairs for two-sum has time complexity_____.
Hint
It examines combinations of pairs rather than using direct lookup.
Answer
O(n²)
- 87The hash-table solution to two-sum stores each element together with the_____where it was seen.
Hint
The problem asks for positions, not only values.
Answer
index
- 88For an element x in two-sum, the algorithm checks whether it previously saw the complement_____.
Hint
The complement must satisfy x plus the complement equals k.
Answer
k-x
- 89The hash-table solution to the two-sum problem runs in_____time.
Hint
Each array element is processed with expected constant-time table operations.
Answer
O(n)

Ask anything
We've read this whole study set, so questions about it get the best answers.