-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingAnalysis.java
More file actions
93 lines (83 loc) · 2.91 KB
/
SortingAnalysis.java
File metadata and controls
93 lines (83 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
/**
* COMP 215: Design and Analysis of Algorithms:
* Programming Assignment 1
*
* The <code>SortingAnalysis</code> class provides a
* main method for a program that validates the run-time
* complexity and asymptotic run-time complexity for
* different kinds of sort methods.
*
* This code will be used to compare the worst case,
* best case, and average case run times for Insertion Sort,
* Merge Sort, Heap Sort, and Quick Sort
*
*
* Created:
* [01/24/2016], [Melany Diaz]
* With assistance from: Dr. Gerry Howser
*
* Modifications: <
* [01/24/2016], [Melany Diaz],
* [implemented code to sort in increasing and
* decreasing orders, made an array of user
* inputed size of random integers]
*
* [01/27/2016], [Melany Diaz],
* [discovered arrays have a toString
* method, so changed how to print the arrays,
* refactored main class and update documentary,
* added timing mechanisms]
*
* [01,31,2016], [Melany Diaz],
* [perfected comments and headers(specifying
* pre and post conditions), added assert
* statements and changed the program so that
* it wouldn't just compare integers, but any
* comparable object, had the user choose if
* the array should be printed,confirmed use of
* preconditions, postconditions and invariants]
*
* [02,07,2015], [Melany Diaz],
* [Changed the class to work with the second project]
*
* @author [Melany Diaz]
*
*/
public class SortingAnalysis
{
/*
* Instance Variables
*/
//Objects of each sorting class
static InsertionSort insertionSort = new InsertionSort();
static MergeSort mergeSort = new MergeSort();
static HeapSort heapSort = new HeapSort();
static QuickSort QuickSort = new QuickSort();
/**
* The main function initiates execution of this program.
* Makes the worst, best, and average arrays and then times how
* long it takes to sort them in ascending order.
* Will print out each array if they are smaller than 20 elements
* and will print the amount of time it took to sort them.
* The user will specify how big each array will be.
*
* @param String[] args not used in this program
**/
public static void main(String[] args)
{
/**
* find the time complexities of each sorting style
*/
System.out.println("InsertSort" + "\n" + "n; Random; Best; Worst");
insertionSort.run();
System.out.println("MergeSort" + "\n" + "n; Random; Best; Worst");
mergeSort.run();
System.out.println("HeapSort" + "\n" + "n; Random; Best; Worst");
heapSort.run();
System.out.println("QuickSort" + "\n" + "n; Random; Best; Worst");
QuickSort.run();
}//end main
}//end class