To construct an open hash table using the given input data (30, 20, 56, 75, 31, 19) and the hash function h(K) = K mod 11, we'll perform the following steps:
The Steps
Initialize an array (hash table) of size 11.
Apply the hash function to each input number to determine its position in the hash table.
Handle collisions using an open addressing method like linear probing.
Let's illustrate this in Python:
# Function to perform open hashing with linear probing
def open_hashing(keys):
table_size = 11
hash_table = [None] * table_size
for key in keys:
index = key % table_size
while hash_table[index] is not None:
index = (index + 1) % table_size
hash_table[index] = key
return hash_table
# Input data
input_data = [30, 20, 56, 75, 31, 19]
# Construct the open hash table
hash_table = open_hashing(input_data)
print("Open Hash Table:", hash_table)
# Find the largest number of key comparisons in a successful search
largest_comparisons = max([(key % 11) + 1 for key in input_data])
print("Largest number of key comparisons in a successful search:", largest_comparisons)
# Find the average number of key comparisons in a successful search
average_comparisons = sum([(key % 11) + 1 for key in input_data]) / len(input_data)
print("Average number of key comparisons in a successful search:", averag