Revise the threaded sort application to improve the performance by applying one or more of the principles to improve the efficiency of I/O. Provide the improved code.Here is the code:public class MergeSort { // The mergeSort method returns a sorted copy of the // String objects contained in the String array data. /** * Sorts the String objects using the merge sort algorithm. * * @param data the String objects to be sorted * @return the String objects sorted in ascending order */ public static String[] mergeSort(String[] data) { if (data.length > 1) { String[] left = new String[data.length / 2]; String[] right = new String[data.length – left.length]; System.arraycopy(data, 0, left, 0, left.length); System.arraycopy(data, left.length, right, 0, right.length); left = mergeSort(left); right = mergeSort(right); return merge(left, right); } else { return data; } } /** * The merge method accepts two String arrays that are assumed * to be sorted in ascending order. The method will return a * sorted array of String objects containing all String objects * from the two input collections. * * @param left a sorted collection of String objects * @param right a sorted collection of String objects * @return a sorted collection of String objects */ public static String[] merge(String[] left, String[] right) { String[] data = new String[left.length + right.length]; int lIndex = 0; int rIndex = 0; for (int i=0; i data = new ArrayList(); BufferedReader in = new BufferedReader(new FileReader(file)); // Read the data from the file until the end of file is reached while (true) { String line = in.readLine(); if (line == null) { // the end of file was reached break; } else { data.add(line); } } //Close the input stream and return the data in.close(); return data.toArray(new String[0]); }}SortTest:import java.io.File;import java.io.IOException;/** * The class SortTest is used to test the threaded and non-threaded * sort methods. This program will call each method to sort the data * contained in the four test files. This program will then test the * results to ensure that the results are sorted in ascending order. * * Simply run this program to verify that you have correctly implemented * the threaded sort method. The program will not verify if your sort * uses threads, but will verify if your implementation correctly * sorted the data contained in the four files. * * There should be no reason to make modifications to this class. */public class SortTest { public static void main(String[] args) throws IOException { File[] files = {new File(“enable1.txt”), new File(“enable2k.txt”), new File(“lower.txt”), new File(“mixed.txt”)}; // Run Sort.sort on the files long startTime = System.nanoTime(); String[] sortedData = Sort.sort(files); long stopTime = System.nanoTime(); double elapsedTime = (stopTime – startTime) / 1000000000.0; // Test to ensure the data is sorted for (int i=0; i 0) { System.out.println(“The data returned by Sort.sort is not sorted.”); throw new java.lang.IllegalStateException(“The data returned by Sort.sort is not sorted”); } } System.out.println(“The data returned by Sort.sort is sorted.”); System.out.println(“Sort.sort took ” + elapsedTime + ” seconds to read and sort the data.”); // Run Sort.threadedSort on the files and test to ensure the data is sorted startTime = System.nanoTime(); // Commenting out /*String[] threadSortedData = Sort.threadedSort(files); stopTime = System.nanoTime(); double threadedElapsedTime = (stopTime – startTime)/ 1000000000.0; // Test to ensure the data is sorted if (sortedData.length != threadSortedData.length) { System.out.println(“The data return by Sort.threadedSort is missing data”); throw new java.lang.IllegalStateException(“The data returned by Sort.threadedSort is not sorted”); } for (int i=0; i 0) { System.out.println(“The data return by Sort.threadedSort is not sorted”); throw new java.lang.IllegalStateException(“The data returned by Sort.threadedSort is not sorted”); } } System.out.println(“The data returned by Sort.threadedSort is sorted.”); System.out.println(“Sort.threadedSort took ” + threadedElapsedTime + ” seconds to read and sort the data.”); } } */
Why Choose Us
- 100% non-plagiarized Papers
- 24/7 /365 Service Available
- Affordable Prices
- Any Paper, Urgency, and Subject
- Will complete your papers in 6 hours
- On-time Delivery
- Money-back and Privacy guarantees
- Unlimited Amendments upon request
- Satisfaction guarantee
How it Works
- Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
- Fill in your paper’s requirements in the "PAPER DETAILS" section.
- Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
- Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
- From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.