Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 "get"method 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

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions