Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment is to write a java program to do the following: Determine the number of unique words she used (in a provided collection of

This assignment is to write a java program to do the following:

  1. Determine the number of unique words she used (in a provided collection of her works).
  2. Compare the time required to determine this number across several different algorithms
  3. Determine the three most common words in this collection and how many times each occurs.
  4. Use the code provided in ProbeHT

import java.util.HashMap;

import java.util.Set;

import java.util.TreeSet;

/**

* An incomplete Hashtable using probing. The get and put functions are stubs only.

* They must be implemented. A completed implementation need not handle

* deletions. Therefore, the implementation need not worry about tombstones,

* rehashing to reduce the size of the table, or rehashing to reduce the number

* of tombstones

*

* @param the type of key

* @param the type of value

*/

public class ProbeHTInc implements Map206Interface {

/**

* Small inner class to group together key,value pairs

*/

protected class Pair {

/** The key, cannot be changed */

final L key;

/**

* The value. It can be changed as a second put with the key will change the

* value

*/

W value;

/**

* Initialize the node

*/

public Pair(L ll, W ww) {

key = ll;

value = ww;

}

/** Print the node, and all subsequent nodes in the linked list */

public String toString() {

return "<" + key + ", " + value + ">";

}

}

/** A Constant .. One of the cases in which static are acceptable

* This one specifies the maximum number of tombstones allowed before

* rehashing for tombstone accumulation

*/

/** When the hashtable needs to grow, by what factor should it grow */

private static final double GROWTH_RATE = 2.0;

/** How full the table should be before initiating rehash/growth */

private static final double MAX_OCCUPANCY = 0.60;

/** The default size of the backing array */

private static int DEFAULT_CAPACITY = 1009;

/** The array in which the hashtable stores data */

private Pair[] backingArray;

/** The number of active items in the hashtable */

private int itemCount;

/** Default initialization */

public ProbeHTInc() {

this(DEFAULT_CAPACITY);

}

/**

* Initialize a hashtable of the given size

*

* @param size the size of the hashtable to create

*/

@SuppressWarnings("unchecked")

public ProbeHTInc(int size) {

// Cannot make an array in which you mention a parameterized type.

// So just make the generic array. This is a narrowing cast so it does not

// even need to be explicitly case.

backingArray = new Pair[size];

itemCount = 0;

}

/**

* The hash function. Just uses the java object hashvalue.

* @param key the Key to be hashed

* @return the hash value

*/

private int hash(K key) {

return Math.abs(key.hashCode()) % backingArray.length;

}

/**

* The number of active items in the hashtable

* @return The number of active items in the hashtable

*/

public int size() {

return itemCount;

}

/**

* Add a key-value pair to the hashtable. If the key is already in the

* hashtable, then the old value is replaced. Otherwise this adds a new

* key-value pair

* Be sure to update itemCount as needed.

*

* @param key the key

* @param value the value

*/

public void put(K key, V value) {

}

@SuppressWarnings("unchecked")

/**

* Rehash the current table. This should be done rarely as it is expensive

* @param newSize the size of the table after rehashing

*/

private void rehash(int newSize) {

Pair[] oldArray = backingArray;

itemCount = 0;

backingArray = new Pair[newSize];

for (int i = 0; i < oldArray.length; i++) {

if (oldArray[i] != null) {

put(oldArray[i].key, oldArray[i].value);

}

}

}

/**

* Get the value associated with the key

* @param key the key whose value is sought

* @return the associated value, or null

*/

public V get(K key) {

return null;

}

@Override

/**

* Does the hashtable contain the key

* @param key the key

* @return true iff the key is in the hashtable

*/

public boolean containsKey(K key) {

return null != get(key);

}

@Override

/**

* The complete set of keys active in the hashtable.

* @return a set containing all of the keys in the hashtable

*/

public Set keySet() {

TreeSet set = new TreeSet<>();

for (Pair pr : backingArray) {

if (pr!=null) {

set.add(pr.key);

}

}

return set;

}

/**

*

*/

public static void main(String[] args) {

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

What do you understand to be the meaning of turnover?

Answered: 1 week ago

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago