Question: HOW DO I FIND THE AVERAGE PROBE COUNT? import java.util.ArrayList; public class HashTable { private HashObject hashTable[]; // linear probing table char typeOfHashTable; int tableSize;

HOW DO I FIND THE AVERAGE PROBE COUNT?

import java.util.ArrayList;

public class HashTable {

private HashObject hashTable[]; // linear probing table

char typeOfHashTable;

int tableSize;

int n; // number of objects stored in hashTable

// create hashTables and choose between liner probing and double hashing

@SuppressWarnings("unchecked")

public HashTable(int indicator) {

tableSize = HashTest.tableSize;

//tableSize =8;

n = HashTest.numberOfObjects;

//n = 5;

HashObject.probe = 0;

hashTable = new HashObject[tableSize];

if (indicator == 1) {

typeOfHashTable = 'L';

} else if (indicator == 2) {

typeOfHashTable = 'D';

}

}

void insert(K key, V value) {

if (typeOfHashTable == 'L') {

LinearProbing(key, value);

} else if (typeOfHashTable == 'D') {

DoubleHashing(key, value);

}

}

private void LinearProbing(K key, V hashValue) {

HashObject hashObject = new HashObject(key, hashValue);

int home = getHashCode(key);

int index = home;

for (int i = 0; i < tableSize; i++) {

if (hashTable[index] == null) {

hashTable[index] = hashObject;

HashObject.probe++;

return;

} else if (hashTable[index].equals(hashObject)) {

HashObject.duplicate++;

return;

}else{

HashObject.probe++;

index = getNextProbe(home, i);

}

}

}

private void DoubleHashing(K key, V hashValue) {

HashObject hashObject = new HashObject(key, hashValue);

int home = getHashCode(key);

int index = home;

for (int i = 0; i < tableSize; i++) {

if (hashTable[index] == null) {

HashObject.probe++;

hashTable[index] = hashObject;

return;

} else if (hashTable[index]== hashObject) {

HashObject.duplicate++;

return;

}else{

HashObject.probe++;

index = getNextProbe(key, home, i);

}

}

}

private int getNextProbe(int home, int i) {

return (home + i) % tableSize;

}

private int getHashCode(K key) {

int i = key.hashCode();

int value = i % tableSize;

if (value < 0) {

value += tableSize;

return value;

}

return value;

}

private int getNextProbe(K key, int home, int i) {

return (home + (i * getSecondHashCode(key)) )% tableSize;

}

private int getSecondHashCode(K Key) {

int i = Key.hashCode();

int value = 1+(i % (tableSize-2));

if (value < 0) {

value += tableSize;

return value;

}

return value;

}

// all keys in the table

public Iterable keys() {

ArrayList keys = new ArrayList();

for (int i = 0; i < tableSize; i++) {

if (hashTable[i] != null) {

keys.add(hashTable[i].getKey());

}

}

return keys;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To find the average probe count for the given Java implementation of a hash table with linear probing and double hashing you need to calculate the tot... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!