Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

This code should be in Java Create a simple hash table You should use an array for the hash table, start with a size of

This code should be in Java

Create a simple hash table

  • You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time.
  • You should create a class to hold the data, which will be a key, value pair
  • You should use an integer for you key, and a String for your value.
    • For this lab assignment, we will keep it simple
  • Use a simple hash function
    • If your key is an integer, just mod by the table size
    • Your key can be the integer value in the data
  • For collision resolution, use open addressing with Linear Probing

    Your program should include:

    • A class to hold the key-value pairs
    • A class to hold the array of key-value pairs
    • A method to add data to the table
      • Since the hash function and collision resolution method are so simple, you could include them in this method, or you could write separate methods for them.
      • You should read your input from a file, I will write up a test file to test your code. The input file will look like this:
         39482 Sam 359353 Luck 977535 Barney 546943 Moe 70984 Dr.Max 
    • A method to double the size of the array when needed, and a rehash method to go along with it.
    • A way to print out the contents of the hash table for testing.
    • You may test your program with a separate class for the driver, or just put a main method in the same class as the array of key-value pairs.
    • You should implement a search method: Given a key, return the value associated with that key.
    • Put in a delete method that doesn't mess up the hashing indexes.
    • Make sure you aren't rehashing deleted items when you double the size of the array.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions