import java.util.Scanner; /** Driver.java - for the lab on the Randomized Quick Select algorithm. */ public class Driver { public static void main(String [] args) { // Standard tests: create shuffled arrays containing the integers // from 1-n, where n is 1 million and 10 million. Array a1 = new Array(100000); Array a2 = new Array(1000000); // Run randomized quick select to get the (0.3n)th smallest element. int result1 = a1.rqs(30000); int result2 = a2.rqs(300000); System.out.printf("Test 1 %s.\n", result1 == 30000 ? "succeeded" : "failed"); System.out.printf("Test 2 %s.\n", result2 == 300000 ? "succeeded" : "failed"); int ops1 = a1.getOps(); int ops2 = a2.getOps(); System.out.printf("First test had this many operations: %d\n", ops1); System.out.printf("Second test had this many operations: %d\n", ops2); System.out.printf("Ratio should be about 10. Actual ratio: %f\n", 1.0 * ops2 / ops1); // Now, let's do an interactive test. System.out.printf("\nInteractive test:\n"); Scanner kbd = new Scanner(System.in); System.out.printf("How large do you want the array? "); int size = Integer.parseInt(kbd.nextLine()); System.out.printf("I will find the k-th smallest element. What is k? "); int k = Integer.parseInt(kbd.nextLine()); Array a3 = new Array(size); int result3 = a3.rqs(k); System.out.printf("Test 3 %s.\n", result3 == k ? "succeeded" : "failed"); } }