Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started