Search in sources :

Example 41 with Stopwatch

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();
}
Also used : Stopwatch(edu.princeton.cs.algs4.Stopwatch)

Example 42 with Stopwatch

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();
}
Also used : Stopwatch(edu.princeton.cs.algs4.Stopwatch)

Example 43 with Stopwatch

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;
    }
}
Also used : Stopwatch(edu.princeton.cs.algs4.Stopwatch)

Example 44 with Stopwatch

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;
    }
}
Also used : Stopwatch(edu.princeton.cs.algs4.Stopwatch)

Example 45 with Stopwatch

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;
    }
}
Also used : Stopwatch(edu.princeton.cs.algs4.Stopwatch)

Aggregations

Stopwatch (edu.princeton.cs.algs4.Stopwatch)62 ArrayList (java.util.ArrayList)5 In (edu.princeton.cs.algs4.In)2 VisualAccumulator (util.VisualAccumulator)2 Exercise21_ComparableTransactions (chapter2.section1.Exercise21_ComparableTransactions)1 RedBlackBST (chapter3.section3.RedBlackBST)1 LinearProbingHashTable (chapter3.section4.LinearProbingHashTable)1