Question: This program is a Big-O notation, linked lists, hash tables, trees, collections, sets, lists example problem. This is a pretty beginner class so we havent

This program is a Big-"O" notation, linked lists, hash tables, trees, collections, sets, lists example problem. This is a pretty beginner class so we havent discussed any major topics. We are using abstract methods and exception handling to deal with this problem/ arrays and other basic java topics binary object files.I will include an example as reference to how much we have used. Essentially this is an excersie on Big-"O" notation, linked lists, hash tables, trees, collections, sets, lists. PLEASE INCLUDE HASHTABLE CLASS HASHTABLE TESTERCLASS AND LINKED LIST CLASS, if possible with a screen shot of it working. PLEASE DO NOT HANDWRITE AS IT IS VERY HARD TO READ, asked this same Q and literally could not read 20 percent of the response

Project 1: The minus operation on sets

In the lecture on linked lists and sets, we saw code which performed the intersection of two sets A andB(written as A B) and the union of two sets (written as A U B). Both of these operations return a new set (i.e., they do not change the original sets A or B).

Another common relationship between two sets is A minus B (written as A B). In this operation, a new set is created which contains each element in set A unless that same element is also in set B.

As you can see from the picture, two interesting relationships exist:

(A B) U (A B) = A

(A B) U (A B) U (B A) = A U B

In this project, enhance the Set class on Blackboard in two ways:

1.Create a new method named minus with the following heading:

public Set minus(Set otherSet)

It should perform the minus operation described above, where the new set returned from the method contains all of the elements in calling object minus any element also in otherSet.

2.Create an equals method which returns true if all of the elements in the calling object are in the set passed as a parameter, and vice versa. The method should have a heading of:

public boolean equals(Set otherSet)

In a different class containing main, test your new minus and equals methods with the following four test casess:

Case 1: calling object = {C, E, G, A} and otherSet = {E, C, F}

Case 2: calling object = {Carlos, John, Alice} and

otherSet = {John, Henry, Maria}

Case 3: calling object = {5, 1, 3} and otheSer = {1, 3, 5, 7, 9}

Case 4: calling object = {5} and otherSet = {}

In each case, print the contents of 5 sets: A, B, (A B), (A B), and

(A B) U (A B). Notice that the last set should have the same elements as set A. Use the equals method to prove this point.

Along with a printout of your program containing main and your enhanced version of the Set class, submit PrintScreen(s) for each test case showing the results of the 5 required sets and the test for equality of the last set with the first set listed.

EXAMPLE OF CODE NOT PART OF THE QUESTION FOR CONTEXT

/* HashTable.java - Create an array of LinkedLists to demonstrate a hash table * Author: Chris Merrill (from textbook) * Topic: Topic 12 * Project: Demonstration * Description: * * This class represents a hash table used to store any number of Strings * in an array of LinkedLists. * * It has been enhanced to delete a Node containing a String using an iterator * to find that node * * The algorithm for determining which table to store a String is simply * summing the ASCII values of every character in the String, then taking * the modulo of the sum when divided by the size of the hash table * * In this demo, the size of the table will be 7 Linked Lists * * Instance variables * LinkedList[] hashArray * int SIZE (size of array) * * Methods * no-arg constructor * computeHash(String) * contains(String) * put(String) * remove(String) */ public class HashTable { // Instance variables private LinkedList[] hashArray = null ; private int hashTableSize = 0 ; public HashTable(int size) { // Must have a positive number of linked lists hashTableSize = size ; if (hashTableSize <= 0) { System.out.println("Error - size must be non-negative: " + size) ; System.exit(0) ; } // Create the linked lists that will correspond to each bucket in the table hashArray = new LinkedList[hashTableSize] ; for (int i=0 ; i < hashTableSize ; i++) hashArray[i] = new LinkedList() ; HashTableTester.debug("Hash table created with size: " + hashTableSize) ; } // Compute the "hash" (or the index) of a String by summing the ASCII // values of the characters in the String, modulo the size of the hash table private int computeHash(String stringToHash){ int hash = 0 ; for (int i = 0 ; i < stringToHash.length() ; i++) { hash += stringToHash.charAt(i) ; } hash = hash % hashTableSize ; HashTableTester.debug("Hash for String \"" + stringToHash + "\": " + hash) ; return hash ; } // Determine if a String is already in the hash table public boolean contains(String target) { int hash = computeHash(target) ; LinkedList list = hashArray[hash] ; return list.contains(target) ; } // Stores a String in the hash table (only if it is not already in the table) public void add(String stringToStore) { int hash = computeHash(stringToStore) ; // Get hash value if (hashArray[hash].contains(stringToStore)) { // Already in the list HashTableTester.debug("String \"" + stringToStore + "\" is already in the list -- not added") ; } else { // Add to the list HashTableTester.debug("String \"" + stringToStore + "\" added to list " + hash) ; hashArray[hash].addToStart(stringToStore) ; } } // Remove a String in the hash table. Return true if it was present, // return false if it wasn't present. Uses an iterator to find the // String and, if present, delete it public boolean remove(String stringToRemove) { // Where should this String be in the table? int hash = computeHash(stringToRemove) ; // Use an iterator to find that String and delete it LinkedList.Iterator iterator = hashArray[hash].iterator() ; while (iterator.hasNext()) { if (iterator.peek().equals(stringToRemove)) { iterator.delete() ; // deleted HashTableTester.debug("String \"" + stringToRemove + "\" deleted from list " + hash) ; return true ; } else { iterator.next() ; } } HashTableTester.debug("String \"" + stringToRemove + "\" could not be deleted from list " + hash) ; return false ; // not found } // toString() uses the toString() for each Linked List public String toString() { String stringOfLists = "" ; for (int i = 0 ; i < hashTableSize ; i++) { stringOfLists += " table " + i + ": " + hashArray[i] + " " ; } return stringOfLists ; } } // end HashTable class 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!