Skip to content
Official PYQ · 2004

GATE CS 2004 Q7 — Arrays, Stacks and Queues

Explain with AI

Given the following input (4322,1334,1471,9679,1989,6171,6173,4199)(4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function xx mod 1010, which of the following statements are true?

  1. 9679,1989,41999679, 1989, 4199 hash to the same value

  2. 1471,61711471, 6171 hash to the same value

  3. All elements hash to the same value

  4. Each element hashes to a different value

Choose one option
View worked solution

Answer: C

The hash function is defined as h(x)=x(mod10)h(x) = x \pmod{10}, which simply returns the last digit (units digit) of the integer xx.

Let's compute the hash value for each element in the input list:

  • h(4322)=4322(mod10)=2h(4322) = 4322 \pmod{10} = 2
  • h(1334)=1334(mod10)=4h(1334) = 1334 \pmod{10} = 4
  • h(1471)=1471(mod10)=1h(1471) = 1471 \pmod{10} = 1
  • h(9679)=9679(mod10)=9h(9679) = 9679 \pmod{10} = 9
  • h(1989)=1989(mod10)=9h(1989) = 1989 \pmod{10} = 9
  • h(6171)=6171(mod10)=1h(6171) = 6171 \pmod{10} = 1
  • h(6173)=6173(mod10)=3h(6173) = 6173 \pmod{10} = 3
  • h(4199)=4199(mod10)=9h(4199) = 4199 \pmod{10} = 9

Now, let's evaluate the given statements:

  • Statement I: 9679,1989,41999679, 1989, 4199 hash to the same value.
    Since h(9679)=h(1989)=h(4199)=9h(9679) = h(1989) = h(4199) = 9, this statement is True.
  • Statement II: 1471,61711471, 6171 hash to the same value.
    Since h(1471)=h(6171)=1h(1471) = h(6171) = 1, this statement is True.
  • Statement III: All elements hash to the same value.
    This is False as different elements yield different hash values (e.g., 2,4,1,9,32, 4, 1, 9, 3).
  • Statement IV: Each element hashes to a different value.
    This is False because there are multiple collisions (e.g., 14711471 and 61716171 both hash to 11).

Therefore, only statements I and II are true, which corresponds to option C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions