// dsaI_17_31.java SJ import fi.joensuu.cs.tra.Set; import java.util.Random; import java.util.TreeSet; import java.util.HashSet; public class dsaI_17_31_skeleton { public static void main(String[] args) { int N = 10; if (args.length > 0) N = Integer.valueOf(args[0]); Set S1 = new Set(); Set S2 = new Set(); Set S3 = new Set(); Random r = new Random(42); Integer x, y; for (int i = 0; i < N; i++) { x = r.nextInt(N*2); S1.add(x); y = r.nextInt(N*2); S2.add(x-y); S3.add(x+y); } System.out.println("S1: " + S1); System.out.println("S2: " + S2); System.out.println("S3: " + S3); System.out.println("twoOutFromThreeTRA: " + twoOutFromThree(S1, S2, S3)); TreeSet TS1 = new TreeSet(S1); TreeSet TS2 = new TreeSet(S2); TreeSet TS3 = new TreeSet(S3); System.out.println("twoOutFromThreeJava: " + twoOutFromThree(TS1, TS2, TS3)); } // main() /** * 31. Write an algorithm that creates a ”two out of three” intersection * of sets. Algorithm gets as pa- rameter three sets, and creates a new * set that contains those elements that are contained in ex- actly two * input sets (not all three, not less than two). You can use either * JavaAPI sets, or TRA- library set. Do not change the input sets. What * is the time complexity of your algorithm? **/ // TRA version public static Set twoOutFromThree(Set A, Set B, Set C) { // TODO return null; } // twoOutFromThree() // JavaAPI version public static TreeSet twoOutFromThree(TreeSet A, TreeSet B, TreeSet C) { // TODO return null; } // twoOutFromThree() } // class dsaI_17_31