Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do in either C++ or Java. Only need to implement type D. Thank you. Write a class, MyHashTable to implement a hash table that uses

Do in either C++ or Java. Only need to implement type D. Thank you.

image text in transcribedimage text in transcribed

Write a class, MyHashTable to implement a hash table that uses Open Hashing, and insert it in a test program The hash table efficiently stores records and uses character strings as keys. The member functions will be: MyHashTable(int sz); boolean insert (String key, String record); // returns false if key is present, true otherwise // create an empty has table of fixed size sz // key is a string of lower case alphabetic chars w/o spaces String isPresent(String key);// returns the record if key is present, null otherwise boolean delete(String key); int membership); void listAll) // returns false if key is not present, true otherwise // returns the number of records in the data structure // list all members of the hash table in the order that // they are stored. Precede each one with an integer giving // the index in the table of that record The hash function MUST BE as follows: int hash(String ky, int tableSize) [ int m - ky.lengthO; int sum0 for(int i-m-1;i>-0;i--) // use unsigned ints in C/C++ sum - sum*31 + (int) (ky.charAt(i)); // automatically applies mod 2 132) sum sum & 0x7fffffff return sum % tables ize // remove the sign bit // % works fine with a positive dividend Your program will read a text file from System.in that contains text commands. In response to each command your program will output one or more lines of text to System.out Here are the commands: L SZ Q sz D sz R // create a hash table of size sz that uses linear probing // create a hash table of size sz that uses quadratic probing // create a hash table of size sz that uses double hashing with h_2(y) R (y mod R) // empty the hash table and reset the statistics A soap:Keeps you clean /7 Insert record "Keeps you clean" with "soap" as its key. // Print one of the lines "Key soap inserted at location #", "Key soap already exists". OR // "Table has overflowed". In the latter case, the record isn't inserted // Delete the record that has "sin" as its key // Print one of the lines "Key sin deleted" OR "Key sin not found" R sin S fortune // Search for the key "fortune" // Print one of the lines "Key fortune:" then the record corresponding to that key, // then the text " found at location #" , OR Key fortune not found" // Print the line "Membership is #" where # is the number of records stored in the table // Print a list of the elements in the Table in the order of their position in the table, // one record per line in the form "# key: Record, where # is the position in the table // Print the following three lines: // Total probes during inserts = # // Total probes during unsuccessful searches = #

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions