📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      Complete a simple hash function for a string s that sums the ASCII values of its characters and then takes the modulo of a prime number M. def simple_hash(s,

      • M :     hash_val = 0     for char in s:         _________ # Line to complete (add ASCII value)     _________ # Line to complete (modulo operation)     return hash_val
      A hash_val += ord(char) ; hash_val = hash_val % M Correct Answer Incorrect Answer
      B hash_val += char ; hash_val %= M Correct Answer Incorrect Answer
      C hash_val = ord(char) ; hash_val = hash_val % M Correct Answer Incorrect Answer
      D hash_val += ord(char) * M ; hash_val = hash_val % M Correct Answer Incorrect Answer
      E hash_val += ord(char) ; return hash_val % M Correct Answer Incorrect Answer

      Solution

      The correct answer is A

      Practice Next
      ask-question