Display the percentage of table had been occupied

Assignment Help Computer Engineering
Reference no: EM132095880

Please help! Any help is appreciated. Answer only in Java, nothing else.

Use HashTable.java and HashFunction.java from below

Write a driver program and modify the HashTable.java to build a Hash table with the specifications as follows:

(a) A table size is 128 slots.

(b) The input data are randomly generated UNIQUE upper case data names with eight characters in length (Each name has to be unique).

(c) Use the generated name for both key and Element value (KVpair.)

(d) Use the same name as the key for sfold function in HashFunction class to create the hash code for the table entry.

(e) Add those data names to the table start with empty table until the table is 40% full.

(f) Display the percentage of table had been occupied during the insertion.

(g) Use the linear prob method for handling collisions and calculate total accumulated collision sum (need to modify the hashInsert method provided in following code).

(h) If the name had collision on the Hash Table, display all names of those collide keys.

(i) Display the total number of collision.

(j) Continue to run the program until the table is 60% and display the total number of collision.

HashTable.java

import java.io.*;

public class HashTable, E> {
private int M;
private KVpair[] HT;

private int h(Key key) {
return M - 1;
}

private int p(Key key, int slot) {
return slot;
}

@SuppressWarnings("unchecked") // Generic array allocation
HashTable(int m) {
M = m;
HT = (KVpair[])new KVpair[M];
}
/** Insert record r with key k into HT */
void hashInsert(Key k, E r) {
int home; // Home position for r
int pos = home = h(k); // Initial position
for (int i=1; HT[pos] != null; i++) {
pos = (home + p(k, i)) % M; // Next pobe slot
assert HT[pos].key().compareTo(k) != 0 :
"Duplicates not allowed";
}
HT[pos] = new KVpair(k, r); // Insert R
}
/** Search in hash table HT for the record with key k */
E hashSearch(Key k) {
int home; // Home position for k
int pos = home = h(k); // Initial position
for (int i = 1; (HT[pos] != null) &&
(HT[pos].key().compareTo(k) != 0); i++)
pos = (home + p(k, i)) % M; // Next probe position
if (HT[pos] == null) return null; // Key not in hash table
else return HT[pos].value(); // Found it
}

}

HashFunction.java

import java.io.*;
import java.math.*;

public class HashFunction
{

int sfold(String s, int M) {

int intLength = s.length() / 4;
int sum = 0;
for (int j = 0; j < intLength; j++) {
char c[] = s.substring(j*4,(j*4)+4).toCharArray();
int mult = 1;
for (int k = 0; k < c.length; k++) {
sum += c[k] * mult;
mult *= 256;
}
}

char c[] = s.substring(intLength * 4).toCharArray();
int mult = 1;
for (int k = 0; k < c.length; k++) {
sum += c[k] * mult;
mult *= 256;
}

return(Math.abs(sum) % M);
}
int h(String x, int M) {
char ch[];
ch = x.toCharArray();
int xlength = x.length();

int i, sum;
for (sum=0, i=0; i sum += ch[i];
return sum % M;
}
int h(int x) {
return(x % 16);
}

}

Reference no: EM132095880

Questions Cloud

Evaluate the opportunities and threats that exist : The next stage of the marketing audit is for you to consider the market for your organisation and evaluate the opportunities and threats that exist
Write the method called stringsletters : Write the method called Strings.letters(String str) that returns a string of letters that only occur once in str, in the same order that they appear.
Write a program that gets ints from a file : Write a program that gets ints from a file. These are numerators and denominators, and you are to create Fractions.
A paint calculator that gives the customer the area : Create a CustomerData.txt file with 10 Customers including Customers Name, Room Name, Length of the Room, Width of the room and Height of the room.
Display the percentage of table had been occupied : The input data are randomly generated UNIQUE upper case data names with eight characters in length (Each name has to be unique).
Ongoing presence in the channel : What have some retailers in your area done to justify their ongoing presence in the channel?
Write pseudocode and translate it to c-program : Ask users to input a series of integers. The input will end with the number 0. Assume users will never input more than 10 integers before input 0.
What are the major differences you have experienced : What are the major differences you have experienced in buying a product through a traditional retail store
Batch of salami was sold to supermarkets : This batch of salami was sold to Supermarkets Pty. Ltd. for sale in its supermarket in Melbourne. On 20 July 2018, Ann purchased a package of salami

Reviews

Write a Review

 

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd