Question

Title: Implementation of chained hashing in Java or Python Description: Implement a double linked list with...

Title: Implementation of chained hashing in Java or Python

Description:

  1. Implement a double linked list with a procedure for adding list elements.
  2. Implement a hash table using chaining and the linked list discussed above.
    1. Use Array size m = 7
    2. A hash function of: h = k mod 7
  3. Insert 100 random key values into the table. Key values should be between 0 and 99.
  4. Implement a Search procedure that tells whether a particular key value is in the hash table.
  5. Search for key values between 0 to 10 in the hash table, and print out whether they were found.

You might find the following useful in doing this lab:

  • Chapter 11 of your textbook
  • The Chapter 11 PowerPoint slides in Blackboard
  • The pseudocode below

Example pseudocode:

Create HashTable (T)

Do 100 times:

   CHAINED-HASH-INSERT(T, randomKeyValue);

End Do

Do for x between 0 and 10:

If (CHAINED-HASH-SEARCH(T,x))

PRINT(Key value x found in Hash Table);

Else

PRINT(Key value x not found in Hash Table);

end If

End Do

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 import random class Node: def __init__(self, next=None, prev=None, key=None): self.next = next # reference to next node in DLL self.prev = prev # reference to previous node in DLL self.key = key class DoublyLinkedList: def __init__(self): self.head = None def insert(self, key): if self.head is None: self.head = Node(key=key) else: node = Node(next = self.head, key=key) self.head = node class HashTable: def __init__(self, size): self.size = size self.table = [DoublyLinkedList() for _ in range(size)] def insert(self, key): hash_val = key%self.size if not self.search(key): self.table[hash_val].insert(key) def search(self, key): hash_val = key%self.size node = self.table[hash_val].head while(node is not None): if key==node.key: return True node = node.next return False table = HashTable(7) for i in range(100): table.insert(random.randint(0, 99)) for i in range(10): print(f"Found {i} in table" if table.search(i) else f"Not Found {i}")

: class Node: definit (self, next=None, prev=None, key=None): self.next = next # reference to next node in DLL self.prev = prtable = HashTable(7) for i in range (100): table.insert (random.randint(0, 99)) for i in range (10): print(fFound {i} in tab

Reply in case of any doubts

Add a comment
Know the answer?
Add Answer to:
Title: Implementation of chained hashing in Java or Python Description: Implement a double linked list with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly...

    Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly linked lists", as well as "hashing with chaining using doubly linked lists". Notice this program is complete except it doesn't include the remove function. Write the remove function and test it with the rest of the program including the given main program. Upload your C++ source file. ---Here is the referenced program: "hashing with chaining using singly linked lists". Below this...

  • C programming Let's try to use the template below to implement a Set with double hashing....

    C programming Let's try to use the template below to implement a Set with double hashing. Here we assume the Set contains names with 3 characters long. Since it is a Set, we do not need to have an explicit value for each key. We will use a token value of 1 if a name belongs to the Set. Let's reuse the exact hash functions we have seen in example in Part 7 of the lecture notes, page 3. As...

  • C++: Create a class called "HashTable" This class will implement hashing on an array of integers...

    C++: Create a class called "HashTable" This class will implement hashing on an array of integers Make the table size 11 Implement with linear probing. The hash function should be: h(x) = x % 11 Create search(), insert() and delete() member functions. Search should return the index of where the target is located, insert should allow the user to insert a value, and delete removes the desired value from the table. In main perform the following: 1. Insert: 17 11...

  • Insert elements into a hash table implemented using chain hashing, as an array of linked list...

    Insert elements into a hash table implemented using chain hashing, as an array of linked list in which each entry slot is as a linked list of key/value pairings that have the same hash (outcome value computed using certain hash function). You are allowed to use “Hash Function”, h(k) = k % x where, x is the value you will need to decide to use, that you find appropriate for this implementation. The main requirements are the following: 1. Input:...

  • C programming Problem 3 [Set via Hashing] As mentioned in the lecture, a hash table can...

    C programming Problem 3 [Set via Hashing] As mentioned in the lecture, a hash table can be used to implement a Set ADT. Let's try to use the template below to implement a Set with double hashing. Here we assume the Set contains names with 3 characters long. Since it is a Set, we do not need to have an explicit value for each key. We will use a token value of 1 if a name belongs to the Set....

  • Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function...

    Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function has already been implemented for you. // hash.CPP program to implement hashing with chaining #include<iostream> #include "hash.hpp" using namespace std; node* HashTable::createNode(int key, node* next) { node* nw = new node; nw->key = key; nw->next = next; return nw; } HashTable::HashTable(int bsize) { this->tableSize= bsize; table = new node*[tableSize]; for(int i=0;i<bsize;i++) table[i] = nullptr; } //function to calculate hash function unsigned int HashTable::hashFunction(int key)...

  • Implement a software program in C++ t stores and searches the Student records using double-hashing algorithm.  Double...

    Implement a software program in C++ t stores and searches the Student records using double-hashing algorithm.  Double hashing uses the idea of applying a second hash function to key when a collision occurs.   The software program will be based on the following requirements: Development Environment: If the software program is written in C++, its project must be created using Microsoft Visual Studio 2017. If the software program is written in Java, its project must be created using NetBeans v8.2. Algorithm: If...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

  • The task of this project is to implement in Java Hash Table structure using Linear Probing...

    The task of this project is to implement in Java Hash Table structure using Linear Probing Collision Strategy.   You can assume that no duplicates or allowed and perform lazy deletion (similar to BST). Specification Create a generic class called HashTableLinearProbe <K,V>, where K is the key and V is the value. It should contain a private static class, HashEntry<K,V>. Use this class to create array to represent Hashtable:             HashEntry<K,V> hashtable[]; Implement all methods listed below and test each method...

  • Questions for Hashing and Skiplists (a) The next two questions relate to the following hashing setup...

    Questions for Hashing and Skiplists (a) The next two questions relate to the following hashing setup table size is 11 elements . hash keys are lower-case alphabetic strings . the hash function is h(k) code(last Letter (k)) mod 1 1 Where last Letter extracts the last letter from its input and code returns an integer representing the position of the letter in the alphabet (starting at zero). So, for example h(anna) returns 0, h(mob) returns 1 and h(noon) returns 2...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT