Posted: November 25th, 2015

Hash Maps

Hash Maps

provide exposure to building a new generic data structure. Specifically, this project will involve building a new Set structure that maintains the “add” counts of its unique values so that they can be iterated in sorted order with respect to how many times they’ve been added to the set. The Set implementation will be optimized for efficient add/remove/contains over efficient iteration, based on the assumption that we’ll generally be modifying the structure more often than accessing its values in sorted order. 1. [70] Create a new class OccurrenceSet that implements Set. Your OccurrentSet implementation should create and maintain a HashMap<t, integer=””>; doing so will allow you to easily track the integer “add” count for each value in the set. All methods should function as specified in the Set documentation. Additionally:

<t, integer=””>• (10) The add and add All methods will need to keep track of how many times a value has been added to the set. We are optimizing for efficient add, so add should be O(1) and add All should be O(n) for n added values.

<t, integer=””> • (10) The remove, remove All, and retain All methods should remove the necessary values from the set completely (i.e., not just decrements their counts). We are optimizing for efficient remove, so remove should be O(1) and remove All should be O(n) for n removed values.

<t, integer=””>• (10) The contains and contains All methods should behave as documented and operate in O(1) and O(n) time (i.e., for n query values), respectively. • (10) The size method should return the number of unique values currently in the set (i.e., not considering “add” counts). This method should be O(1). The clear and is Empty methods should behave as documented.

<t, integer=””>• (20) The iterator and to Array methods should return an Iterator or array, respectively, with elements sorted by their “add” counts in ascending order. We are optimizing for efficient add/remove/contains over iteration, but these methods should still be O(n lg n). The Iterator remove method does not need to remove the element from the set (see extra credit). Hint: Creating a new List and using the Collections sort method is reasonable here, though note that you’ll need to implement a Comparator object so that the values can be sorted by their associated counts (we’ll discuss this in class).

<t, integer=””>• (10) Add a to String method that prints the elements in the list in sorted order (i.e., ascending with respect to their “add” counts). This method should be O(n lg n). 2.

<t, integer=””> [10] Create a Main class that creates a few Occurrence Sets of various types to test the functionality of your new data structure.

<t, integer=””> For example, a test like:

<t, integer=””>Occurance Set intSet = new Occurance Set();

<t, integer=””>intSet.add(1); i

<t, integer=””>ntSet.add(3);

<t, integer=””>intSet.add(5);

<t, integer=””>intSet.add(5);

<t, integer=””>intSet.add(3);

<t, integer=””>intSet.add(3);

<t, integer=””>intSet.add(3);

<t, integer=””>System.out.println(intSet);

<t, integer=””>OccuranceSet stringSet = new OccuranceSet();

<t, integer=””>stringSet.add(“hello”);

<t, integer=””>stringSet.add(“hello”);

<t, integer=””>stringSet.add(“world”);

<t, integer=””> stringSet.add(“world”);

<t, integer=””>stringSet.add(“world”);

<t, integer=””>stringSet.add(“here”);

<t, integer=””>System.out.print ln (stringSet); Should have the output: [1, 5, 3] [here, hello, world] You’ve now got a data structure which will allow you to easily do things like sort words with respect to word counts without ever needing to write this code again (in Java, at least)! Yay! J 3.

<t, integer=””> [20] Write code that is clear and efficient. Specifically, your code should be indented with respect to code blocks, avoid code that is commented out or otherwise unused, use descriptive and consistent class/method/variable names, etc. 4. [+10] (Extra credit) Implement your own Iterator class to be returned by the iterator method above. Implement the remove method of the Iterator such that the current value is removed from the set.

PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET A GOOD DISCOUNT

Expert paper writers are just a few clicks away

Place an order in 3 easy steps. Takes less than 5 mins.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Live Chat+1-631-333-0101EmailWhatsApp