Multiple choice general knowledge

When using a hash, which function will give you the parent of the entry with index i?

  1. Decimal division, i / 2

  2. Multiplication, i * 2

  3. Integer division, i / 2

  4. Multiplication, i * 2 + 1

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When using a hash (implemented as an array), the parent of the entry at index i is found using integer division: floor(i/2). For example, index 6's parent is at index 3 (6/2=3), and index 5's parent is also at index 2 (5/2=2.5→2). Decimal division would give incorrect fractional results, while multiplication would give child indices, not the parent.