Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I n the Hash Sets lab w e saw how a hash set could b e written using array - based lists for slots. Similar
the Hash Sets lab saw how a hash set could written using arraybased lists for slots. Similar the comparisons did Assignment would like able compare the efficiencies different types hash sets.
Use the Word. module store Word objects
Use the file miserables. Miserables Victor Hugo your test text. The file very large executing your tests may take a few minutes. not resubmit this file part your assignment submission!
Insert every word the test file into A word defined a string that has space characters and consists only letters. simplicity, ignore any words that contain punctuation you don't have strip off the punctuation, you can just ignore Convert the word lower case before inserting into the
Determine how many comparisons were needed insert all the words into the that data stored only once you are really counting the number comparisons needed insert a Word once, then the number comparisons reject the word already being the don't care about the difference between the two types comparison.
Determine the individual Word that had the most comparisons attached
When retrieving the comparisons from the hash set, walking through every element the hash set, not looking for the words again that will change the number comparisons.
Create your hash set with a load factor and initial size
Write the following function process the test file and insert all its words into a hash set:
def ords:
Retrieves every Word ariable and inserts into
Each Word object contains the number
comparisons required insert that Word object from
ariable into
Use: ordsariable,
Parameters:
the already open file containing data evaluate
the insert the words into
Returns:
None
and the following function extract the comparison counts and word with the most comparisons from the hash set:
def otal:
Sums the comparison values all Word objects
Use: total, ord otal
Parameters:
a hash set Word objects
Returns:
total the total all comparison fields the
Word objects
ord the word having the most comparisons
Put these functions the PyDev module functions. and test them from The output from this program must look like:
Using arraybased list
Total Comparisons:
Word with maximum comparisons :
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