🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: String Matching — KMP and Rabin-Karp: all 10 questions

Quiz: String Matching — KMP and Rabin-Karp · Question 7 of 10

In Rabin-Karp, why compare the letters when two hashes are equal?

In Rabin-Karp, why compare the letters when two hashes are equal?

  1. A.To make the code longer
  2. B.Hashes are always different for different strings
  3. C.To compute the next hash
  4. D.Different strings can have the same hash (a collision), so equal hashes do not prove a match
Answer & explanation

Correct answer: Different strings can have the same hash (a collision), so equal hashes do not prove a match

With a modulus, many strings share each hash value; a letter check removes false matches.

Can you get the rest right without peeking?

Take the timed Quiz: String Matching — KMP and Rabin-Karp quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →