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
b random.randint
return lambda x m: a hashx b m
# Function to hash a string
def hashstringself word:
return hashstringword self.mthy
# function: increment
# given a word, increment its count in the countmin sketch
def incrementself word:
# your code here hashval self.hashfunrepword self.m
self.countershashval
# function: approximateCount
# Given a word, get its approximate count
def approximateCountself word:
# your code here hashval self.hashfunrepword self.m
return self.countershashval
# Example usage:
# Initialize CountMinSketch
numcounters
cms CountMinSketchnumcounters
# Increment counts for words
words apple "banana", "apple", "orange", "apple", "banana"
for word in words:
cmsincrementword
# Get approximate counts
printApproximate counts:"
for word in words:
printfword: cmsapproximatecountword is this right
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
