Question: Exercise 4 please (in Java or Python) Let A=a1,,an and B=b1,,bm be two sets of integers, 1xi1000. Consider the problem of finding their intersection, i.e.,

 Exercise 4 please (in Java or Python) Let A=a1,,an and B=b1,,bmbe two sets of integers, 1xi1000. Consider the problem of finding their

Exercise 4 please (in Java or Python)

Let A=a1,,an and B=b1,,bm be two sets of integers, 1xi1000. Consider the problem of finding their intersection, i.e., the set C of all the numbers that are in both A and B. Exercise 1 (5 pts) Design and implement a brute-force algorithm as a method for solving this problem and determine its efficiency class. Write the pseudo-code as comments in the source code. Exercise 2 (10 pts) Design and implement a presorting-based algorithm as a method for solving this problem and determine its efficiency class. Write the pseudo-code as comments in the source code. Exercise 3 (10 pts) Design and implement a (n+m) efficiency algorithm as a method to solve this problem. Hint: Look up "Hash Function" or related terms. Write the pseudo-code as comments in the source code. Exercise 4 (15 pts) Implement all three algorithms as separate methods and do empirical testing using the 2 data sets provided on BlackBoard. The input files begin with 2 integers NM(NM) representing the size of the input sets. Each subsequent N lines contains an integer in set A. Following the N lines, each subsequent M lines contains an integer in set B. The output should display the set C containing the intersecting values as well as the execution times in seconds for each of these 3 algorithms for the 2 data sets (or 6 total runs). Hint: the HashSet class in the Java Collections Framework (as well a dictionary in Python) uses hashing internally. Which algorithm performs the best in each test case? Write your answers either as a comment in your submitted source code. Example Input: Enter the filename: in1.txt 53 23 21 34 65 12 12 15 18 Example Output: Brute Force Intersection: 12 Time(s): Presorting Intersection: 12 Time(s): Hashing : Intersection: 12 Time(s)

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!