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

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

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.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();
       } catch (FileNotFoundException ex) {

By purchasing this solution you'll be able to access the following files:
SolutionData.txt and

for this solution

or FREE if you
register a new account!

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.

Upload a file
Continue without uploading

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