Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DESCRIPTION: In this assignment you are required to implement sets of integers using sorted singly linked lists. Tus, the elements of a set have to

image text in transcribed

DESCRIPTION: In this assignment you are required to implement sets of integers using sorted singly linked lists. Tus, the elements of a set have to be stored in a singly linked lst in increasing order. Therefore, after every operation the singly linked ist has to remain SORTED Youwl have to write a Java clss SLLSet for this purpose. To implement the singly linked list nodes you may use the Java class SLLNode provided in this assign- ment. You are not allowed to use any predeined Jaa ethods or classes froan Java API, other than for input and output .A set is an unordered collection of elements with no repetitions. Ecamples are the consisting of unbers the set of inteermbers or the set of real 1,2,30, For this assigument we will only be considering representing finite sets of integers. Examples: 0,31, 78, 1000), 4,5, 890,65535, 0,1,2- .65531.65535), are all valid sets, . The union of two sets, say A ad B, is written as AU B and is the set which contains all elements in ethe A or B or both. Examp: A 3,8, 14, 15 and B = {2,8,9. 15. 100), then AUB = {2,3, 8.9. I 4, 15. 10))(notice that there nre no repeated elements in a se The intersection of two sets A and isitten as AnB and is the set which contains the elements that are common to A and B. Examples: If A = {3.8, 14, 15} and B = {2.8.9. 15. 100], then An B = {8.15). If A = { 17.20.38} and B = {200} then An B = {], which is termed the empty set. . The difference of two sets A and is written as AB and is the set containing those elements which are in A and are not in B. Example: If A = {3,8, 14.15) and B = {2.8. 9. 15. 100). then A \ B = {314} and B \ A-(2.9. 10 You mayuse the folloingJava class SLLNode: int value SLLNode next public SLLNode(int SLLNode n) value- i; next Classes SLLNode and SLLSet mst be contained in the same package. Class SLLSet has only the followin instance fields 1) an integer to store the size of the set, i.e., the nmber of its elements 2) a reference to the beginning of the linked list (a reference variable of type SLLNode). All instauce fields are private. Clas SLLSet contains at least the following constructors: public SLLSot)-constricts an empty SLLSet ("elnpty" moans with zero ele public SLLSet int sortedArray constructs an SLLSet object that con tains the integers in the input array. Note that the arry is sorted in increasing order and it does not contain repetitors. This constroctor has to be efficient in terms of rumning time and memory usage- Class SLLSet contains at least tbe following metbods: public int getSize returns the size of thia set. public Sti.Set copy returns a deep copy of this SLLSet. The meaning of deep is that the two objects cannot share any piece of memory. Thus the copy represents a set with the same elements as this set, but the two inked lists cannot have ode objocts in common public boolean isln(int v): . returns true if integer v is an element of this SLLSet. It returns false othernise. public void add(int v) - adds v to this SLLSet if v was not already an ele- ment of thia StSet. It does nothing otherwise public void renove(1nt v):-remonesv from this SLLSetifv was an clement of this SLLSet. It does nothing otherwise public SLLSet union (SLLSet s): returns a nea SLLSet which represents the union of this SLLSet and the input SLLSet s. This method has to be efficient in terms of runningtime and memory usage, in other words the amount of operations may be at most a constant value times m' where m is the sum of the 20s of the two sets. Morcoxer, the amount of additional memory used, apart from the memory for the inut and ntput sets, mny not be larger thnn a constant valuc. A constant val means bere a value which does not grom as the sizes of the lists change. Partial marks will be awarded inefficient implementations. public SLLSet intersection(SLLSet 8): returns a new SLLSet ich repro- sents the intersection o this SLLSet and the inpat SLLSet 8. This method has to be efficient in ems of ruaning time and memory usage, in other words the amount of operatios may be at most a constant value times , whee is the sum of the sizes of the tmo sets. Moreoner, the amount of additional memory used, apart from the memory for the input and output sets, may not be larger than a constant vlue. A costant value eas here aale which dos not grow as the sixes o the lists change. Partial marks ill be awarded for inefficient inmplementations. public SLLSet difference(SLLSet s): retus a new SLLSet which represents the difference betneen this SLLSet ad the input SLLSet , .e., thiss. No eficiency requirements are imposed here. public static SLLSet union SLLSet skrray) returns a new object repre- senting the uiou of the sets in the array. public String toString) returns a string representing the set, with the ele- ments listed in increasing order and separated by commas

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

More Books

Students also viewed these Databases questions

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago