Question: # your code here # Generating random coefficients a and b for hash function ax + b a = random.randint ( 1 , 1 0

# your code here # Generating random coefficients a and b for hash function ax + b
a = random.randint(1,100)
b = random.randint(1,100)
return lambda x, m: (a * hash(x)+ b)% m
# Function to hash a string
def hash_string(self, word):
return hash_string(word)% self.mthy
# function: increment
# given a word, increment its count in the countmin sketch
def increment(self, word):
# your code here hash_val = self.hash_fun_rep(word, self.m)
self.counters[hash_val]+=1
# function: approximateCount
# Given a word, get its approximate count
def approximateCount(self, word):
# your code here hash_val = self.hash_fun_rep(word, self.m)
return self.counters[hash_val]
# Example usage:
# Initialize CountMinSketch
num_counters =100
cms = CountMinSketch(num_counters)
# Increment counts for words
words =["apple", "banana", "apple", "orange", "apple", "banana"]
for word in words:
cms.increment(word)
# Get approximate counts
print("Approximate counts:")
for word in words:
print(f"{word}: {cms.approximatecount(word)}") is this right

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!