python code. Below is the code for parallel list implementation of dictionary ADT. Modify the code below to handle collision using double hashing technique. Use the following hash functions: h(k) = k mod n, where is the number of slots in the hash table h’(k) = 7 - (k mod 7) and handles collisions by placing an item in the first available cell of the series A[(i + f(j)) mod N] for j = 1, 2, 3, ..., where f(j) = j*h’(k). import os class Dictionary: def __init__(self, size): self.keys = [None] * size self.values = [None] * size self.n = 0 self.size = size

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

use python code.

Below is the code for parallel list implementation of dictionary ADT. Modify the code below to
handle collision using double hashing technique. Use the following hash functions:
h(k) = k mod n, where is the number of slots in the hash table
h’(k) = 7 - (k mod 7)
and handles collisions by placing an item in the first available cell of the series
A[(i + f(j)) mod N] for j = 1, 2, 3, ..., where f(j) = j*h’(k).

import os
class Dictionary:
def __init__(self, size):
self.keys = [None] * size
self.values = [None] * size
self.n = 0
self.size = size
def __str__(self):
keys_str = "{"
if not self.empty():
for i in range(0, self.size - 1):
keys_str += "({},{}),".format(self.keys[i], self.values[i])
keys_str += "({},{})".format(self.keys[self.size - 1], self.values[self.size - 1])
return keys_str + "}"
def empty(self):
return self.n == 0
def dictionary_size(self):
return self.n
def hash(self, key):
return key % self.size

def insert_item(self, key, item):
if self.n == self.size:
print("Dictionary Overflow")
else:
index = self.hash(key)
self.keys[index] = key
self.values[index] = item
self.n += 1

def remove_item(self, key):
index = self.hash(key)
if self.keys[index] is None:
print("Can't remove the item. Key not found...")
else:
self.keys[index] = None
self.values[index] = None
self.n -= 1
def find_item(self, key):
index = self.hash(key)
if self.keys[index] is None:
return -1
else:
return self.values[index]

dictionary = Dictionary(5)
dictionary.insert_item(1, 2)
dictionary.insert_item(2, 6)
dictionary.insert_item(3, 9)
dictionary.insert_item(1, 10)
print(dictionary)
print(dictionary.find_item(3))
print(dictionary.find_item(1))
print(dictionary.remove_item(1))
print(dictionary)

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY