Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must be done in python. You need to complete the hasing function. Information + Question: Code Given (Please complete the hasing funtion) A hashtable has

Must be done in python.

You need to complete the hasing function.

Information + Question:

image text in transcribed

Code Given (Please complete the hasing funtion)

image text in transcribed

A hashtable has been created, and is using the following simple hash function: h(key) = key 90 size where size is the capacity of the hashtable. You need to define a function called hashing() which simulates a list of keys being inserted, in the order given, into the hashtable. The function should return a representation of the hashtable as a list - where the keys are shown in their positions and the value None is used to represent unused positions. The hashing() function will be passed four inputs: 1. the list of keys to be inserted (you can assume there will be no duplicate keys in the list) 2. the size of the hashtable (you can assume this will be a prime number) 3. the word 'linear', 'quadratic' or 'double' to indicate the kind of probing to be performed following a collision 4. if the third input is 'double', this fourth input represents the value, q, that will be used in the second hash function during double-hashing. This second hash function will be: h'(key) = q-(key 90 q). Otherwise, if linear or quadratic probing is performed, this fourth input will be None. You should then simulate the keys being inserted in the order given in the list, into a hash table of the given size. To resolve collisions, you should use linear probing, quadratic probing or double-hashing as specified by the third input. The output of the function should be a list illustrating the used and unused positions of the hashtable (used positions display key values, unused positions display None). For example, the code: values [26, 54, 94, 17, 31, 77, 44, 51] linear-hashing (values, 13, 'linear', None) quadratic-hashing (values, 13, 'quadratic',None) double hashing (values, 13, 'double', 5) print ('Linear-n', linear) print ('Quadratic -In',quadratic) print 'Double-n', double) would produce the output: Linear- [26, 51, 54, 94, 17, 31, 44, None, None, None, None, None, 77] Quadratic [26, None, 54, 94, 17, 31, 44, None, 51, None, None, None, 77] Double [26, None, 54, 94, 17, 31, 44, 51, None, None, None, None, 77]

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

Step: 3

blur-text-image

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions