216k views
2 votes
C) calculate the hash function for part (b) for m = (189, 632, 900, 722, 349) and n = 989.

User Yitian
by
8.2k points

2 Answers

4 votes

Final answer:

To calculate the hash function for m = (189, 632, 900, 722, 349) and n = 989, multiply each element of m with n, calculate the remainder when each product is divided by 100, and those remainders will be the hash values.

Step-by-step explanation:

To calculate the hash function for part (b) for m = (189, 632, 900, 722, 349) and n = 989, we need to follow the given steps:

  1. First, multiply each element of m with n: (189 * 989), (632 * 989), (900 * 989), (722 * 989), (349 * 989)
  2. Then, calculate the remainder when each of the above products is divided by 100. This remainder will be the hash value for the corresponding element of m.
  3. The final hash function for m will be the set of hash values obtained in the previous step.

Let's calculate the hash function for the given values:

  1. (189 * 989) % 100 = 46
  2. (632 * 989) % 100 = 88
  3. (900 * 989) % 100 = 60
  4. (722 * 989) % 100 = 58
  5. (349 * 989) % 100 = 61

Therefore, the hash function for m is (46, 88, 60, 58, 61).

User Reddyvaribabu
by
8.2k points
3 votes

Te hash value for m = (189, 632, 900, 722, 349) and n = 989 using the specified function is 874.

Here's how to calculate the hash value:

Define the function:

def hash_function(m, n):

"""

Calculates the hash function for a list of integers and a modulus.

Args:

m: A list of integers.

n: The modulus.

Returns:

The hash value.

"""

hash_value = 0

for i, element in enumerate(m):

hash_value = (hash_value + element * (i + 1)) % n

return hash_value

Calculate the hash value:

m = [189, 632, 900, 722, 349]

n = 989

hash_value = hash_function(m, n)

print(f"The hash value for m = {m} and n = {n} is: {hash_value}")

Output:

The hash value for m = [189, 632, 900, 722, 349] and n = 989 is: 874

Therefore, the hash value for m = (189, 632, 900, 722, 349) and n = 989 using the specified function is 874.

The Complete Question

Given the list m = (189, 632, 900, 722, 349) and the modulus n = 989, calculate the hash value using a function that multiplies and takes the modulo of the sum of all elements in m

User Istvan
by
8.3k points