Implement a complete version of a hash table

Assignment Help Python Programming
Reference no: EM131670703

Task 1

Implement a complete version of a hash table using Linear Probing to resolve collisions. Include implementations for the following 4 functions:
- getitem (self, key): Returns the value corresponding to key in the hash table. Raises a KeyError if key does not exist in the hash table. Called by table[key]
- setitem (self, key, value): Sets the value corresponding to
key in the hash table to be value. Raise an exception if the hash

table is full and the key does not exist in the table yet. Called by
table[key] = value

- contains (self, key): Returns True if key is in the table and
False otherwise.
- hash(self, key): Calculates the hash value for the given key.

Use the hash function given below.

def hash_value (self , key ):
a = 101
h = 0
for c in key :
h = (h a +ord( c)) % self. table_size
return h

Task 2

Download from Moodle the dictionary files english_small.txt, english_large.txt and french.txt.

For each of these dictionaries, time how long it takes to read all words in it into the hash table (i.e. wall time). Do this for each of the following table_size values: 210000, 209987, 400000 and 399989 and 202361. Present the wall times recorded in a table.

Write a short analysis reporting what values work best and which work poorly. Explain why these might be the case

Task 3

Modify your hash table implementation to now track the number of collisions as well as the average probe length. For the latter, it is advisable to track the total probe length in an instance variable. The average probe length is the total probe length divided by the number of items on the table.

Using collisions, probe length and wall time, choose appropriate values of a (in your hash function) and table_size. You want to find values that perform well across all three files. For this task use a maximum table size of 400000.

You should try at least 10 values, and explain your choice by presenting all data behind your reasoning recorded in a table

Task 4

Modify your hash table from the previous tasks to:
- use Quadratic Probing to resolve collisions.
- implement dynamic hashing, by doubling the size of the underlying array (and rehashing) every time the load exceeds 2
Compare the number of collisions, probe length and running time found when loading each dictionary against the best combination found using the Linear Probing hash table.

Task 5

Implement a hash table which uses Separate Chaining to resolve collisions. It is a good idea to first implement and test the Linked List separately. Compare the performance of Separate Chaining against the linear probe above.

Background
In most large collections of written language, the frequency of a given word in that collection is inversely proportional to its rank in the words. That is to say that the second most common word appears about half as often as the most common word, the third most common word appears about a third as often as the most common word and so on.

If we count the number of occurrences of each word in such a collection, we can use just the number of occurrences to determine the approximate rank of each word. Taking the number of occurrences of the most common word to be max and the relationship described earlier, we can assume that any word that appears at least max/100 times appears in the top 100 words and is therefore common.

The same can be applied as max/1000 times for the next 900 words, rounding out the top 1000 words, considered to be uncommon. All words that appear less than max/1000 times are considered to be rare. In this prac we have been implementing hash tables and so we will use one here to facilitate a frequency analysis on a given text file.

Task 6
Download some ebooks as text files from gutenberg website and use these files as a collection of English. Read these into your Quadratic Probing hash table to count the number of each word in the texts. Considering the data you collected in Task 2, select an appropriate table size for the text files. Use these occurrence counts to construct a table which can be used to look up whether a given word is common, uncommon or rare within written English.

Task 7
Download another ebook from gutenberg website and using your table from Task 6, analyse the percentage of common, uncommon and rare words. If a word is not found in the table, consider it misspelled. Print the percentage of common, uncommon, rare and misspelled words for the given text.

Task 8

Implement the program in Task 3 using Python's dict class. How does the performance of your own implementations compare to Python's in terms of the wall time? What factors may drive the differences? How close can you get to the reference implementation?

Attachment:- Prac Files.zip

Verified Expert

This assignment involves writing code for the python program. Totally 8 tasks are involved. Task 1 involves implement linear probing hashing technique. The task 2 involves reading the text from three files and store in the hash table and analyse the wall time or each of the hash table. The task 3 involves calculating average probe length for each of the hash table with 10 different a values. The task 4 involves implementing quadratic probing and rehashing technique. The task 5 requires to implement separate chaining. Task 7 involves reading the text from book and implement in the hash table. All task are supplied with python program and documentation contains output for each of the task.

Reference no: EM131670703

Questions Cloud

Nation most diverse university : LGBTQ+ status or disability. We take pride in being our nation's most diverse university. We stand for aloha."
Prepare a detailed multi-step income statement : Financial Accounting: Tools for Business Decision Making. Prepare a detailed multi-step income statement with a brief explanation. Assume a 25% tax rate.
Role of journalism in a democracy : So, what have you learned about the role of journalism in a democracy? Do you believe that role or the democracy it supports.
Tip about a prominent politician : The news organization for which you work has received a tip about a prominent politician who holds statewide office and who is running for re-election.
Implement a complete version of a hash table : FIT1008 - Intro to Computer Science - Implement a complete version of a hash table using Linear Probing to resolve collisions and implement dynamic hashing
Interview conducted by email is good or bad : Draw conclusions! Let us know if a story based on an interview conducted by email is good or bad; whether reporters should treat published news stories.
Outline for the final paper : An outline for your final paper is due Sunday by 11:59 pm (post it via the assignment link above).
What role does access to health care and services play : Discuss if poor nutrition is a risk factor for your health problem-Lack of sanitation or open defecation in India.
Overview of the topics you plan : Provide an overview of the topics you plan to cover in your lectures.so how to prepare for the job of lecturer?

Reviews

inf1670703

1/8/2018 4:15:42 AM

He made an awesome solution with regards to on my examination proposition. It was extremely exhaustive and elegantly prepared. I will enlist this expert once more.

inf1670703

11/30/2017 5:34:03 AM

Please find at the attached files some example code that might help with the assignment. Thanks 25435767_1lecture.py 25435736_2referential array.py Please find at the attachment the sample code, please finish as much as you can, at least to task 5. Thank you 25435786_1Julians Live code-20012.zip 25435786_2Julians Live Code-20012 1.zip

len1670703

10/6/2017 8:36:25 AM

Marks For this assessed prac, there are a total of 30 marks. There are 10 marks allocated to your understanding of the solutions and your implementations in the prac overall. In addition to these, the marks for each task are listed with the tasks. A marking rubric is available online for you to know and understand how you will be marked.

len1670703

10/6/2017 8:36:15 AM

Please write test cases for each task.For each critical steps, please write a explanation Thank youObjectives of this practical session To be able to implement and use hash tables in Python. Note: • You should provide documentation and testing for each piece of functionality in your code. Your documentation needs to include pre and post conditions, and information on any parameters used. • Create a new file/module for each task or subtask. • You are not allowed to use the Python built-in dict methods. • Name your files task[num] to keep them organised. Testing For this prac, you are required to write: (1) a function to test each function you implement, and (2) at least two test cases per function. The cases need to show that your functions can handle both valid and invalid inputs. There is no need to test menu functions.

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd