Page 1 of 2 Project 4 Hash Table This project focus is to implement in Java Hash Table structure using Linear Probing Collision Strategy. You can assume that no duplicates are allowed and perform lazy...

1 answer below »
This project focus is to implement in Java Hash Table structure using Linear Probing Collision Strategy. You can assume that no duplicates are allowed and perform lazy deletion (similar to BST). I'm attaching the project file please follow all the direction in the project file. Donot give me solution from chegg or any other internet source. I need plagerism free. The solution must contain two files:HashTableLinearProbe.javaMain.java



Page 1 of 2 Project 4 Hash Table This project focus is to implement in Java Hash Table structure using Linear Probing Collision Strategy. You can assume that no duplicates are allowed and perform lazy deletion (similar to BST). Use: - f(i) = i - default table size = 3 - You may create console menu like or just test methods in main method Menu (type the designated interger value based on the operation you would like to perform): To insert: Type 1 To find: Type 2 To delete: Type 3 To quit: Press 4 Enter choice: Specification • Create a generic class called HashTableLinearProbe , where K is the key and V is the value. • It should contain a private static class, HashEntry. Use this class to create array to represent Hashtable: HashEntry hashtable[]; • Implement all methods listed below and test each method through main method. o Public Boolean insert (K key, V value)  This function inserts entry, rehashes if the table is full, throw error message if the key is invalid or null and return true upon successful insertion or false if duplicate entry o Public V find (K key)  This function check if the key exists in the table. If yes, true value of the key, or null if not found o Public Boolean delete (K key)  Performs lazy deleting by marking the entry as deleted. Return true if deleted , false if it not found in the hashtable o Public int getHashValue(K key) Page 2 of 2  Returns the hash value for the given key or return -1 if not found o Private void rehash()  If the table is full, then doubles the hash table size, rehash everything to the new table, ignore items marked deleted. o Public static void main(String args[])  Methods calls to demonstrate functionality of methods above. Make sure to check with both Integer and String objects • You may use the pseudocode provide in the text, but make sure to have exception handling for invalid input parameters and method calls. Submission Submit the following items on eLearning: 1. README.txt This should identify who you are (name, NetID, etc.), which project you are submitting, what files comprise your project, how you developed and compiled your project (e.g. what IDE or text editor, which version of Java, what compiler options, etc.), and any other information you believe the grader should know or you want the grader to know. Both items should be submitted as a single zipped file named with your lowercase NetID. The file structure should resemble the following example: *-- abc123789.zip |-- README.txt |-- HashTableLinearProbe.java |-- Main.java Specification Submission
Answered 6 days AfterOct 25, 2021

Answer To: Page 1 of 2 Project 4 Hash Table This project focus is to implement in Java Hash Table structure...

Swapnil answered on Oct 28 2021
126 Votes
94608/HashTableLinearProbe.java
94608/HashTableLinearProbe.java
public class HashTableLinearProbe 
{
    private int s;
    private int items;
    private HashEntry ht[];
    public HashTableLinearProbe()
    {
        s = 3;
        ht = new HashEntry[s];
        items = 0;
    }
    private static class HashEntry
    {
  K k;
        V v;
        boolean del;
        HashEntry(K k, V v)
        {
            this.k = k;
            this.v = v;
            del = false;
        }
    }
    public boolean ins(K k, V v) throws IllegalArgumentException
    {
        int hV;
        int c = 0;
        if (!(k instanceof Integer) && !(k instanceof String) || k == null)
        {
            throw new IllegalArgumentException("Invalid Key");
        }
        if (items == s)
        {
            rehash();
        }
        if (find(k) == null)
        {
            hV = getHashValue(k);
            for (int i = hV; c != 2; i++) 
            {
                if (ht[i] == null) 
                {
                    ht[i] = new HashEntry<>(k, v); 
                    items++;
                    return true; 
                }
                if (i == (s-1)) 
                {
                    i = -1; 
                }
                if (i == hV || (i+1) == hV)
                {
                    c++;
                }
            }
        }
        return false; 
    }
    public V find (K k)
    {
        if (!(k instanceof Integer) && !(k instanceof String) || k == null)
        {
            throw new IllegalArgumentException("Invalid Key");
        }
        int hV = getHashValue(k); 
        int c = 0;
        if (items == 0) 
        {
            return null;
        }
        for (int i = hV; c != 2; i++) 
        {
            if (i >= s) 
            {
                break;
            }
            if (ht[i] != null) 
            {
                if ((ht[i].k).equals(k) && ht[i].del == false) 
                {
                    return ht[i].v;
                }
                if (i == (s-1)) 
                {
                    i = -1; 
                }
                if (i == hV || (i+1) == hV)
                {
                    c++;
                }
            }
            else 
            {
                if (i == hV || (i+1) == hV)
                {
                    c++;
                }
                continue;
            }
        }
        return null; 
    }
    public boolean delete(K k)
    {
        if (!(k instanceof Integer) && !(k instanceof String) || k == null)
        {
            throw new IllegalArgumentException("Invalid Key");
        }
        int hV = getHashValue(k); 
        int c = 0; 
        if (items == 0) 
        {
            return false;
        }
        for (int i = hV; c != 2; i++) 
        {
            if (i >= s) 
            {
                break;
            }
            if (ht[i] != null) 
            {
                if ((ht[i].k).equals(k) && ht[i].del == false) 
                {
                    ht[i].del = true; 
                    return true; 
                }
                if (i == (s-1)) 
                {
                    i = -1; 
                }
                if (i == hV || (i+1) == hV)
                {
                    c++;
                }
            }
            else
            {
                if (i == hV || (i+1) == hV)
                {
        ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here