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

  Create a jes function

Create a JES function named level1() and include the relevant behaviours. Specifically, in this level, you only need to detect just one character from the text and the text is only in a single row.

  Write a program to convert an input value from base

Write a program to convert an input value from base 10 to a user selectable base between 2 and 16.

  Write program that is capable of generating a set words

You will write a Python program that is capable of generating a likely set of completion words given the start of a word as input to the program.

  Look up terms in a tech dictionary

Create a program that allows a user to look up terms in a tech dictionary - programming or scripting that is of interest to you, and complete one or more web-based tutorials on the topic.

  Write a non-fruitful function drawequitriangle

Write a non-fruitful function drawEquitriangle(someturtle, somesize) which calls drawPoly from the previous question to have its turtle draw a equilateral triangle

  Compute second order differential equations for capacitor

Compute the 2nd order differential equations for capacitor voltage and inductor current in a series RLC circuit. Provide this derivation in your report.

  Fill in the python code

Fill in the Python code to play Tic Tac Toe. I won't award points unless it runs succesfully. # Tic-Tac-Toe Game def drawBoard(board): # Draws the board using the list of numbers print(" ") print(" ",board[0]," | ",board[1]," | ", board[2]) print("--..

  Implement a triangle class in python

CSc 11300 Spring 2016 Programming Languages. Implement a Triangle class in Python: The triangle is defined by its three side lengths - a, b, and c. The class includes methods that perform the following operations: is_triangle - checks whether the giv..

  Write a program that acts like a simple calculator

You will write a program that acts like a simple calculator for binary numbers. You should read in a string of input that has the format: number operator number.

  Develop a program to solve the anteater bed problem

Develop a program to solve the Anteater Bed and Breakfast problem. Develop this code in its own BandB.py file. Pay very close attention to the instructions, especially about developing the program in incremental stages

  Write a python program that will index a set of documents

You are going to write a python program that will index a set of documents and build a function to search through these documents using the index

  Create a new table called custsum that you also write to xyz

create a new table called custSum that you also write to xyz.db, and that has the following characteristics. This table should have one row per customer record.

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