1. Home
  2. Explore
  3. Computer Science
  4. Hashing and Hash Tables

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Hashing and Hash Tables

  • 89Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Hashing Basics
Searching through randomly positioned books one by one until finding a target is called
.

89 questions

  1. 1
    Searching through randomly positioned books one by one until finding a target is called
    _____
    .
    Hint

    This search method examines items sequentially.

    Answer

    linear search

  2. 2
    The 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

  3. 3
    The result produced by the hashing process is called a
    _____
    .
    Hint

    It is the fixed-size value obtained from a key.

    Answer

    hash

  4. 4
    A 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

  5. 5
    In a hash table, values are stored in an array of
    _____
    .
    Hint

    These are the positions of the underlying array.

    Answer

    slots

  6. 6
    In 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

  7. 7
    The 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

  8. 8
    For an array with mmm 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

  9. 9
    The variable mmm represents the number of
    _____
    in a hash table.
    Hint

    It is the table's capacity.

    Answer

    slots

  10. 10
    A 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

  11. 11
    If 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

  12. 12
    A simple hash function can calculate a string's hash by summing the characters'
    _____
    codes and taking the result modulo mmm.
    Hint

    These numerical codes represent characters.

    Answer

    ASCII

  13. 13
    For the key "inside code", the ASCII sum used in the example is
    _____
    .
    Hint

    This is the sum before applying modulo 30.

    Answer

    1079

  14. 14
    Using the example function with the key "inside code" and m=30m = 30m=30 produces the hash
    _____
    .
    Hint

    Compute 107910791079 modulo 303030.

    Answer

    29

  15. 15
    A 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

  16. 16
    In 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

  17. 17
    In 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

  18. 18
    Hash tables can also be used in
    _____
    to support applications such as secure data processing.
    Hint

    This field studies techniques for protecting information.

    Answer

    cryptography

  19. 19
    The condition that keys in a hash table cannot be repeated is called key
    _____
    .
    Hint

    Each key should identify at most one entry.

    Answer

    uniqueness

  20. 20
    Unlike keys, hash table values
    _____
    be unique.
    Hint

    Multiple keys may legitimately refer to equal values.

    Answer

    do not need to

  21. 21
    A 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

  22. 22
    An array or set cannot normally be used as a key because these objects are
    _____
    .
    Hint

    Their contents can change after creation.

    Answer

    mutable

  23. 23
    Integers, 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

  24. 24
    A 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

  25. 25
    When 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

  26. 26
    The 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

  27. 27
    With 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

  28. 28
    If 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

  29. 29
    When 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

  30. 30
    The 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

  31. 31
    In open addressing, searching alternative spots for an insertion or lookup is called
    _____
    .
    Hint

    The algorithm examines candidate positions one after another.

    Answer

    probing

  32. 32
    The 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

  33. 33
    If 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

  34. 34
    Even 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

  35. 35
    Hashing into mmm 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

  36. 36
    A 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

  37. 37
    Perfect 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

  38. 38
    A 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

  39. 39
    A good hash function distributes keys as
    _____
    as possible over the available hash values.
    Hint

    Its outputs should be spread rather than concentrated.

    Answer

    evenly

  40. 40
    If 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

  41. 41
    A hash function is also considered better when it is computationally
    _____
    .
    Hint

    The function should not require excessive computation.

    Answer

    efficient

  42. 42
    A table with 10 spots and 50 keys has an average of
    _____
    elements per spot.
    Hint

    Divide 50 elements by 10 spots.

    Answer

    5

  43. 43
    When 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

  44. 44
    Creating a larger table and reinserting all existing pairs into it is called
    _____
    .
    Hint

    The table is rebuilt using a new capacity.

    Answer

    rehashing

  45. 45
    A 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

  46. 46
    The ratio used to measure how full a hash table is is n/mn/mn/m, where nnn is the number of inserted elements and mmm is the number of
    _____
    .
    Hint

    The denominator represents table capacity.

    Answer

    slots

  47. 47
    For n=21n = 21n=21 elements and m=30m = 30m=30 slots, the fullness ratio n/mn/mn/m is
    _____
    .
    Hint

    Divide 21 by 30.

    Answer

    0.7

  48. 48
    In open addressing, the ratio n/mn/mn/m cannot exceed
    _____
    because each slot stores at most one element.
    Hint

    The table is full when every slot is occupied.

    Answer

    1

  49. 49
    In separate chaining, the ratio n/mn/mn/m can exceed 1 because one slot can store
    _____
    elements.
    Hint

    A linked list can contain several nodes at one index.

    Answer

    multiple

  50. 50
    The maximum allowed value of n/mn/mn/m before rehashing is called the
    _____
    .
    Hint

    It determines when the table should be resized.

    Answer

    load factor

  51. 51
    If the load factor is 0.750.750.75, a table rehashes as soon as n/mn/mn/m
    _____
    0.750.750.75.
    Hint

    The threshold is crossed rather than merely reached.

    Answer

    exceeds

  52. 52
    With 100 slots and a load factor of 0.750.750.75, inserting element number
    _____
    triggers rehashing.
    Hint

    The first 75 elements produce a ratio of 0.75.

    Answer

    76

  53. 53
    A load factor of 0.750.750.75 is described as a generally good
    _____
    value.
    Hint

    It is commonly chosen when no special tradeoff is required.

    Answer

    default

  54. 54
    Reducing the load factor generally improves time efficiency by reducing collisions but decreases
    _____
    efficiency.
    Hint

    More unused slots are allocated.

    Answer

    space

  55. 55
    Increasing the load factor improves space efficiency but usually reduces
    _____
    efficiency because collisions increase.
    Hint

    More collisions require more searching.

    Answer

    time

  56. 56
    The 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

  57. 57
    For 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

  58. 58
    If 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

  59. 59
    Rehashing 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

  60. 60
    In 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

  61. 61
    The linked-list structure used for each separate-chaining slot contains only the
    _____
    .
    Hint

    This pointer identifies the first node.

    Answer

    head

  62. 62
    The three linked-list operations needed by the implementation are insertion, searching, and
    _____
    .
    Hint

    This operation removes a node with a specified key.

    Answer

    deletion

  63. 63
    Inserting 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

  64. 64
    A 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

  65. 65
    When 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

  66. 66
    A hash table implementation stores its number of slots in a field called the
    _____
    .
    Hint

    It describes how many positions the table has.

    Answer

    capacity

  67. 67
    The 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

  68. 68
    During 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

  69. 69
    When 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

  70. 70
    When a new key/value pair is added, the hash table increments its
    _____
    .
    Hint

    The number of stored nodes has increased.

    Answer

    size

  71. 71
    When a key/value pair is successfully deleted, the hash table
    _____
    its size.
    Hint

    The number of stored elements decreases by one.

    Answer

    decrements

  72. 72
    If 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

  73. 73
    Inserting 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)

  74. 74
    Searching a linked list of length lll for a key has time complexity
    _____
    .
    Hint

    The search may inspect every node in the list.

    Answer

    O(l)

  75. 75
    Deleting 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)

  76. 76
    The 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)

  77. 77
    In 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

  78. 78
    In the worst case, all nnn nodes are in one linked list, making search time
    _____
    .
    Hint

    The list length equals the total number of elements.

    Answer

    O(n)

  79. 79
    With 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

  80. 80
    Because 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)

  81. 81
    Although an individual rehash can cost O(n)O(n)O(n), insertion is O(1)O(1)O(1)
    _____
    because rehashing occurs infrequently.
    Hint

    This analysis averages occasional expensive operations over many cheap ones.

    Answer

    amortized

  82. 82
    In 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)

  83. 83
    Hash 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)

  84. 84
    The space complexity of a hash table is
    _____
    because it stores nnn nodes and a number of slots proportional to nnn.
    Hint

    Both major sources of space grow linearly.

    Answer

    O(n)

  85. 85
    The 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

  86. 86
    A 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²)

  87. 87
    The 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

  88. 88
    For an element xxx in two-sum, the algorithm checks whether it previously saw the complement
    _____
    .
    Hint

    The complement must satisfy xxx plus the complement equals kkk.

    Answer

    k-x

  89. 89
    The 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)

1 of 89
Question 1 of 89

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent