Skip to main contentSkip to solution

How is a hash value calculated using the remainder method?

Solution

✅ Correct Option: 2

The remainder (division) method divides the element by the size of the hash table and uses the remainder as the index. This keeps every hash value between 00 and size−1\text{size} - 1, so it always fits in the table.

h(element)=element mod sizeh(\text{element}) = \text{element} \bmod \text{size}

For example, with a table of size 1010, the element 2525 gives 25 mod 10=525 \bmod 10 = \boxed{5}.


Options 1 and 3: division gives the quotient, not the remainder. This is a common mix-up between "/" or "//" and "%".

Option 4: multiplying makes the value larger and can go beyond the table, so it is not a valid index.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question