Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A set (collection of elements without duplication) as a mathematical model is defined by the java interface below. public interface Set { public boolean isEmpty();

A set (collection of elements without duplication) as a mathematical model is defined by the java interface below.

public interface Set

{ public boolean isEmpty(); // Is the set empty?

public void makeEmpty(); // Make this set empty.

public boolean isMember(int x); // Is x a member of this set?

public void add(int x); // Insert an element x in this set.

public void remove(int y); // Delete an element y from this set.

public void union(Set other, Set result); // result = "this" UNION other

public void intersection (Set other, Set result); // result = "this" INTERSECTION other

public void difference (Set other, Set result); // result = "this" - other

public String toString(); // Overridden toString method that returns the set description as

// a String.

public boolean equals(Object other); // Overridden equals method to check equality of two sets.

}

makeEmpty creates an empty set.

isEmpty returns true if the set is empty, false otherwise.

isMember returns true if x is in the given set, false otherwise.

add inserts an element in the set (without duplication).

remove deletes an element from the set.

A union B is the set of all elements either in A or in B or both.

A intersection B is the set of all elements that are in both, A and B.

A difference B is the set of all elements in A but not in B.

toString returns the description of the set as a String.

equals returns true if the two sets are identical (same elements), false otherwise.

You are required to implement the mathematical model Set of integers as a class that implements the above interface. You must implement this structure as a linked list of elements kept in the increasing sequence. You must implement "isMember", "add", and intersection methods using recursive algorithms. Others can be implemented as you wish.

To test your implementation, write the test program to do the following. As always, all input is read from the input file and all output is produced in the output file. Prompt the user to acquire the names of input and output files.

Create an array of N sets, N is the first data in the input file. // S[0] through S[N-1]

Read commands from the input file, and execute them. After each command, output what was done (like, inserted element xxx in set n) and produce the output relevant to that command. Make sure that your output is self-explanatory and paper conserving. That means, do not output the elements of the set one per line, but output many elements on the same line.

The commands are specified in the following format:

A x n // Insert the integer x in set S[n]

R x n // Delete (Remove) x from S[n]

U n1 n2 n3 // S[n3] = S[n1] union S[n2]

N n1 n2 n3 // S[n3] = S[n1] intersection S[n2]

D n1 n2 n3 // S[n3] = S[n1] difference S[n2]

B x n // Does x belong in set S[n] ?

O n // Output the set S[n]

E n // Is set S[n] empty?

Q n1 n2 // Are two sets S[n1] and S[n2] equal?

INPUT FILE:

10 // This is the number of Sets in the array of Sets E 0 A 24 0 A 423 0 A 76 0 A 12 0 A 8 0 A 64 0 O 0 E 0 B 76 0 R 76 0 R 68 0 B 24 0 B 12 0 B 76 0 A 111 0 O 0 A 76 1 A 55 1 A 12 1 A 43 1 A 876 1 A 98 1 A 64 1 A 34 1 O 1 B 111 1 B 76 1 U 0 1 2 O 2 N 0 1 3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions