Question: Implement a Java test drive following this step: (1) declare and initialize an int N to 10 (change to 1000000 later) declare and new an
Implement a Java test drive following this step: (1) declare and initialize an int N to 10 (change to 1000000 later) declare and new an array of n strings, say, x, which simulates Facebook's user names (2) initialize each string element by using x[i] String.valueof(((int) (Math.random()*100000000))); (just use some random digits to pretend to be username) (3) set a target="345461223" (later on change to x[N/2]) (4) write a loop to perform linear search for the target in x (5) surround the loop using long t0 = System.currentTimeMillis(); //loop long ti = System.currentTimeMillis(); (6) write codes to print out the index position where the target is located at or -1 if target is not present. Print out ti-to as well, which is the time spent on the search (7) modify the your codes of creating x[i] so that x[i] will be sorted increasingly. (8) Run the linear search again. (9) get the BinarySearch.java from BB, modify it to deal with string array. (change "w" to ".equals()", xay to m.compareTo(Y)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
