use of edu.princeton.cs.algs4.Stopwatch in project algorithms-sedgewick-wayne by reneargento.
the class Exercise57_JohnsonsAlgorithm method doExperiment.
private double doExperiment(EdgeWeightedDigraphInterface edgeWeightedDigraph, int source, int dWayHeapChildrenNumber) {
Stopwatch stopwatch = new Stopwatch();
new DijkstraSPDWayHeap(edgeWeightedDigraph, source, dWayHeapChildrenNumber);
return stopwatch.elapsedTime();
}
use of edu.princeton.cs.algs4.Stopwatch in project algorithms-sedgewick-wayne by reneargento.
the class Exercise22_Timings method doExperiment.
private double doExperiment(String[] randomStrings, int sortAlgorithmType) {
int stringsLength = randomStrings[0].length();
Stopwatch stopwatch = new Stopwatch();
if (sortAlgorithmType == LSD_SORT_ID) {
LeastSignificantDigit.lsdSort(randomStrings, stringsLength);
} else if (sortAlgorithmType == MSD_SORT_ID) {
MostSignificantDigit.msdSort(randomStrings);
} else if (sortAlgorithmType == THREE_WAY_STRING_QUICKSORT_ID) {
ThreeWayStringQuickSort.threeWayStringQuickSort(randomStrings);
}
return stopwatch.elapsedTime();
}
use of edu.princeton.cs.algs4.Stopwatch in project algorithms-sedgewick-wayne by reneargento.
the class Exercise17_Sentinels method doExperiment.
private static void doExperiment(int numberOfExperiments, int initialArraySize, Map<Integer, Comparable[]> allInputArrays) {
StdOut.printf("%13s %23s %39s\n", "Array Size | ", "QuickSort Running Time |", "QuickSort W/ No Sentinels Running Time");
int arraySize = initialArraySize;
for (int i = 0; i < numberOfExperiments; i++) {
Comparable[] originalArray = allInputArrays.get(i);
Comparable[] array = new Comparable[originalArray.length];
System.arraycopy(originalArray, 0, array, 0, originalArray.length);
// Default QuickSort
Stopwatch defaultQuickSortTimer = new Stopwatch();
QuickSort.quickSort(array);
double defaultQuickSortRunningTime = defaultQuickSortTimer.elapsedTime();
// QuickSort with no sentinels
Stopwatch quickSortWithNoSentinelsTimer = new Stopwatch();
quickSortWithNoSentinels(originalArray);
double quickSortWithNoSentinelsRunningTime = quickSortWithNoSentinelsTimer.elapsedTime();
printResults(arraySize, defaultQuickSortRunningTime, quickSortWithNoSentinelsRunningTime);
arraySize *= 2;
}
}
use of edu.princeton.cs.algs4.Stopwatch in project algorithms-sedgewick-wayne by reneargento.
the class Exercise18_MedianOf3Partitioning method doExperiment.
private static void doExperiment(int numberOfExperiments, int initialArraySize, Map<Integer, Comparable[]> allInputArrays) {
StdOut.printf("%13s %23s %30s\n", "Array Size | ", "QuickSort Running Time |", "QuickSort with median-of-three");
int arraySize = initialArraySize;
for (int i = 0; i < numberOfExperiments; i++) {
Comparable[] originalArray = allInputArrays.get(i);
Comparable[] array = new Comparable[originalArray.length];
System.arraycopy(originalArray, 0, array, 0, originalArray.length);
// Default QuickSort
Stopwatch defaultQuickSortTimer = new Stopwatch();
QuickSort.quickSort(array);
double defaultQuickSortRunningTime = defaultQuickSortTimer.elapsedTime();
// QuickSort with median-of-three partitioning
Stopwatch quickSortWithMedianOfThreeTimer = new Stopwatch();
quickSortWithMedianOfThree(originalArray);
double quickSortWithMedianOfThreeRunningTime = quickSortWithMedianOfThreeTimer.elapsedTime();
printResults(arraySize, defaultQuickSortRunningTime, quickSortWithMedianOfThreeRunningTime);
arraySize *= 2;
}
}
use of edu.princeton.cs.algs4.Stopwatch in project algorithms-sedgewick-wayne by reneargento.
the class Exercise19_MedianOf5Partitioning method doExperiment.
private static void doExperiment(int numberOfExperiments, int initialArraySize, Map<Integer, Comparable[]> allInputArrays) {
StdOut.printf("%13s %23s %32s %30s\n", "Array Size | ", "QuickSort Running Time |", "QuickSort with median-of-three | ", "QuickSort with median-of-five");
int arraySize = initialArraySize;
for (int i = 0; i < numberOfExperiments; i++) {
Comparable[] originalArray = allInputArrays.get(i);
Comparable[] arrayCopy1 = new Comparable[originalArray.length];
System.arraycopy(originalArray, 0, arrayCopy1, 0, originalArray.length);
Comparable[] arrayCopy2 = new Comparable[originalArray.length];
System.arraycopy(originalArray, 0, arrayCopy2, 0, originalArray.length);
// Default QuickSort
Stopwatch defaultQuickSortTimer = new Stopwatch();
QuickSort.quickSort(originalArray);
double defaultQuickSortRunningTime = defaultQuickSortTimer.elapsedTime();
// QuickSort with median-of-three partitioning
Stopwatch quickSortWithMedianOfThreeTimer = new Stopwatch();
Exercise18_MedianOf3Partitioning.quickSortWithMedianOfThree(arrayCopy1);
double quickSortWithMedianOfThreeRunningTime = quickSortWithMedianOfThreeTimer.elapsedTime();
// QuickSort with median-of-five partitioning
Stopwatch quickSortWithMedianOfFiveTimer = new Stopwatch();
quickSortWithMedianOfFive(arrayCopy2);
double quickSortWithMedianOfFiveRunningTime = quickSortWithMedianOfFiveTimer.elapsedTime();
printResults(arraySize, defaultQuickSortRunningTime, quickSortWithMedianOfThreeRunningTime, quickSortWithMedianOfFiveRunningTime);
arraySize *= 2;
}
}
Aggregations