Answered step by step
Verified Expert Solution
Link Copied!

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

In the Hash Sets lab we saw how a hash set could be written using array-based lists for slots. Similar to the BST comparisons we did in Assignment 8,we would like tobe able to compare the efficiencies of different types of hash sets.
Use the Word.py module to store Word objects inaHashSet.
Use the file miserables.txt(Les Miserables by Victor Hugo),as your test text. The file is very large so executing your tests may take a few minutes. Do not resubmit this file as part of your assignment submission!
Insert every word in the test file into aHashSet. A word is defined as a string that has no space characters and consists of only letters. (For simplicity, ignore any words that contain punctuation - you don't have to strip off the punctuation, you can just ignore it.) Convert the word to lower case before inserting it into the HashSet.
Determine how many comparisons were needed to insert all of the words into the HashSet.(Given that data is stored only once inaHashSet, you are really counting the number of comparisons needed to insert a Word once, then the number of comparisons to reject the word as already being in the HashSet.We don't care about the difference between the two types of comparison.)
Determine the individual Word that had the most comparisons attached toit.
When retrieving the comparisons from the hash set, dosoby walking through every element in the hash set, not by looking for the words again - that will change the number of comparisons.
Create your hash set with a load factor of20 and an initial size of20.
Write the following function to process the test file and insert all its words into a hash set:
def insertwords(fv,hashset):
"""
-------------------------------------------------------
Retrieves every Word infilevariable and inserts into
aHashSet. Each Word object inhashset contains the number
of comparisons required to insert that Word object from
filevariable into hashset.
Use: insertwords(filevariable, hashset)
-------------------------------------------------------
Parameters:
fv- the already open file containing data to evaluate (file)
hashset- the HashSetto insert the words into (HashSet)
Returns:
None
-------------------------------------------------------
"""
and the following function to extract the comparison counts and word with the most comparisons from the hash set:
def comparisontotal(hashset):
"""
-------------------------------------------------------
Sums the comparison values of all Word objects inhashset.
Use: total, maxword =comparisontotal(hashset)
-------------------------------------------------------
Parameters:
hashset- a hash set of Word objects (HashSet)
Returns:
total - the total of all comparison fields in the HashSet
Word objects (int)
maxword - the word having the most comparisons (Word)
-------------------------------------------------------
"""
Put these functions in the PyDev module functions.py and test them from . The output from this program must look like:
Using array-based list HashSet
Total Comparisons: x,xxx,xxx
Word with maximum comparisons 'www': xx,xxx

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions