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
B hash_val += char ; hash_val %= M
C hash_val = ord(char) ; hash_val = hash_val % M
D hash_val += ord(char) * M ; hash_val = hash_val % M
E hash_val += ord(char) ; return hash_val % M
Practice Next

Hey! Ask a query