Question: 2. You are given two arrays of Strings (i) array soccer consists of names of students who play soccer in a large school, and (ii)

2. You are given two arrays of Strings (i) array soccer consists of names of students who play soccer in a large school, and (ii) array volleyball consists of names of students who play volleyball in the school. Notice that there may be students who play both sports. Names can be one word, two words or three words consisting of alphabetic characters. Write methods to perform the following actions: (20 points)

(i) soccerOnly (..) that returns students who play only soccer via a suitable data structure.

(ii) volleyBallOnly(..) that returns students who play only volleyball via a suitable data structure.

(iii) bothSports(..) that returns students who play both sports via a suitable data structure. No duplicates allowed.

Note that (..) means that you may or may not use any parameters for the methods, it would be up to you to decide. Secondly, you can use other data structures to copy the data into, to make the methods efficient. The methods will each return a suitable data structure containing the result. All three methods should run in O(n) time where n is equal to the sum of the sizes of the initial two arrays.

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!