A collection of identification numbers are to be stored in a

A collection of identification numbers are to be stored in a hash table. These numbers are of the following form:

9 characters in length

first character is a capital letter.

(Note: You are to create your own data set and select an appropriate table size.)

The hash code to be used is polynomial hash code (see Section 10.2.1 of the textbook).

The compression function to be used is the division method.

The collision-resolutions strategies (see Section 10.2.2 of the textbook) to be used are:

separate chaining

linear probing

quadratic probing

Solution

As per my knowledge, this can be of some help:

import java.io.*;

import java.util.*;

public class PolyHash {

    public static void main(String[] args) throws Exception {

        if (args.length == 0) {

            System.out.println(\"Error: No files input\");

            System.exit(0);

        }

        String foo = null;

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

            BufferedReader reader = new BufferedReader(new FileReader(args[i]));

            foo = simplify(reader);

            System.out.print(foo);

            int blockSize = Integer.valueOf(args[2]);

            List<String> list = new ArrayList<String>();

            for (int k = 0; k < foo.length() - blockSize + 1; k++) {

                list.add(foo.substring(k, k + blockSize));

            }

            System.out.print(list);

        }

    }

    public static String simplify(BufferedReader input)

            throws IOException {

        StringBuilder sb = new StringBuilder();

        String line = null;

        while ((line = input.readLine()) != null) {

            sb.append(line.replaceAll(\"[^a-zA-Z]\", \"\").toLowerCase());

        }

        return sb.toString();

    }

}

A collection of identification numbers are to be stored in a hash table. These numbers are of the following form: 9 characters in length first character is a ca
A collection of identification numbers are to be stored in a hash table. These numbers are of the following form: 9 characters in length first character is a ca

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site