1. Engineering
  2. Computer Science
  3. create a class for a quotsetquot of integers similar to...

Question: create a class for a quotsetquot of integers similar to...

Question details

Create a class for a set of integers, similar to IntArrayBag java from the textbook, except that only one copy of a value can be stored (no duplicates). You may directly copy any appropriate code from IntArrayBag java. Include the following methods, and answer the given questions in your report: a. A main method creates two sets and demonstrates all of the methods below b. Modify the add method such that it does not add duplicate elements. Use the countOccurences method to determine whether the element already exists. QUESTION: What is the Big-O time for this entire algorithm, including the operations for es? Briefly explain your answer coun A public print method prints all of the values in the set in the order in which they are stored (index #0 is first). Below is an example of calling print for a set with the values 3, 1, 0, 2) c. 3 1 0 2 QUESTION: What is the Big-O time for this method? Briefly explain your answer d. A private getmethod receives an index for an item in the set and returns that element. For a set with the values 3, 1, 0, and 2, calling 2) would return 0. Throw RuntimeException if the index is invalid (see the clone method in IntArrayBag.java for an example) QUESTION: What is the Big-O time for this method? Briefly explain your answer A public static intersection method receives two sets and returns a new set that is the intersection (all common elements). Note that this is similar to the format of the union method in the sample program. For your algorithm, use the get method from above to get elements from one set and the countOccurrences method to determine whether that element is in the second set. For example, the intersection sets {3. 1. O, 2} and {1.3.4} would consist of the values 1 and 3 (in any order). If there are no common elements, the returned set should be empty (size of zero) e. QUESTION: What is the Big-O time for this entire algorithm, including the operations for get and countOccurrences? Briefly explain your answer

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution