A hash table contains 10 buckets and uses linear probing. Hash function: key %…

2022

A hash table contains 10 buckets and uses linear probing. Hash function: key % 10. Insert keys: 43, 165, 62, 123, 142. Where will 142 be inserted? (Assume table size = 8?)

  1. A.

    2

  2. B.

    3

  3. C.

    4

  4. D.

    6

Attempted by 395 students.

Show answer & explanation

Correct answer: D

Final answer: 142 is inserted at index 6.

Reasoning:

  • Hash table has 10 buckets (indexes 0–9). Hash function: key % 10. Linear probing is used to resolve collisions.

  • Insert 43: 43 % 10 = 3 → index 3 empty → place 43 at index 3.

  • Insert 165: 165 % 10 = 5 → index 5 empty → place 165 at index 5.

  • Insert 62: 62 % 10 = 2 → index 2 empty → place 62 at index 2.

  • Insert 123: 123 % 10 = 3 → index 3 occupied → probe to index 4 → index 4 empty → place 123 at index 4.

  • Insert 142: 142 % 10 = 2 → index 2 occupied (62) → probe to index 3 (occupied by 43) → probe to index 4 (occupied by 123) → probe to index 5 (occupied by 165) → probe to index 6 which is empty → place 142 at index 6.

Note: The question statement mentions 10 buckets; the answer 6 depends on using modulus 10. If the table size were actually 8, the insertion positions would change and you should use key % 8.

Explore the full course: Up Lt Grade Assistant Teacher 2025