QuestionQuestion

Problem description: To compare performance of different sorting techniques.
Programming instruction: Write a Java program to implement selection sort, insertion sort, merge sort, and quicksort (may be as four separate methods). For each of the sorting techniques, use four input set in the supplied sample data file to compare their running time. These sorting techniques should achieve sorted data set in increasing order. The sample data file has 4 different data sets. The first set has all random numbers, the second set has all numbers equal, third set has the numbers already sorted in increasing order, and the fourth set has all number sorted in reverse (decreasing order). All data sets have equal number of items. Each of the sorting techniques must be applied separately on each data set and the time (in nanoseconds) to achieve the sorted output in each case must be noted. Each time, before sorting the input set, start the timer and after your sorting is done, stop the timer. The output should be a display of the results similar to the following (YOU DO NOT NEED TO CREATE AN ACTUAL TABLE. HOWEVER, ALL INFORMATION SHOULD BE PRESENT.)

Sorting Technique                Time taken (in nanoseconds)
                                  Data set 1          Data set 2       Data set 3       Data set 4
                                  (all random)         (all equal)    (already sorted)   (reverse sorted)
Selection sort
Insertion sort
Merge sort
Quick sort (with medianof-3 partitioning)
DO NOT USE arrays.sort() OR ANY OTHER IN-BUILT SORTING TECHNIQUES PROVIDED BY Java APIs. Write your own code (or, you may modify codes supplied in class) to implement the sorting technique. Also, note: your program should not be data file dependent.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Programming4 {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
      
       Scanner s = new Scanner(System.in);
       System.out.print("Enter data file name: ");
       String fileName; // = "SortDatafile.txt"; //s.nextLine();
      
       fileName = s.nextLine();
      
       ArrayList< int [] > arrayList = new ArrayList<>();
       try {
            Scanner file = new Scanner(new File(fileName));
            String line;
            while (file.hasNext()) {
                line = file.nextLine();
                arrayList.add(string2IntArray(line));
            }            
       } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage());
       }...
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats